ActionScript 2.0 :: Correct Syntax For Declaring A Variable Within A Loop?
Mar 25, 2007Whats the correct syntax for declaring a variable within a loop? Something like this:[code]
View 1 RepliesWhats the correct syntax for declaring a variable within a loop? Something like this:[code]
View 1 RepliesI'm trying to do something like this:
[Code]....
whats the correct syntax for declaring a variable thats name changes according to a different variable.
Should I declare the _mcContainer var before the loop or no? (performance increase?)
for(var i:uint = _startIndex; i <= _endIndex; ++i){
var _mcContainer:MovieClip = _mcParent["i_" + _position];
}
[Code]....
I have a number of XMLList objects:
_xml.group1..image[i]
_xml.group2..image[i]
_xml.group3..image[i]
_xml.group4..image[i]
_xml.group5..image[i]
Im trying to reference each object thus:
_xml.group[myVariable]..image[i]
But it doesnt work. What's the correct syntax?
is this correct:
getURL("webform1.aspx?id=0&status=I",0,"Get");
I need to pass 2 values
value 1 is id
value 2 is status
I'm using addChild(new nmonster()) to populate an on stage MC from my Library.
Instead of specifying the Symbol, I want to add it using an Array reference, like addChild(new monsterArray[0]()). I've tried a number of variations, but AS3.0 is unforgiving.
I want to declare 8 variables at the class level like this:
Code:
private var graphicDesign1:Sprite;
private var graphicDesign2:Sprite;
private var graphicDesign3:Sprite;
private var graphicDesign4:Sprite;
[code]....
But I would like to do it with a for loop. Is that possible? If so i'm doing it wrong this is what I have.
Code:
for(var i = 1; i < 9; i++){
private var +"graphicDesign"+i:Sprite;
}
Is there a way to do this somehow?
Code:
var someVariable:int = 3;
for(var i:int = 0; i< someVariable; i++){
var mainArr[i]:Array = new Array();//I get an error if I try this
[Code]....
What I want to achieve is pretty basic: I have an input text with instance name (contact_date) and I want the information the user enter in this input field to be kept in a variable that I can reuse later on in my movie.
View 2 RepliesI'm trying to declare arrays inside a for loop, then access them later as if they were declared publicly/globally. This doesn't work:
Code:
playlist = addChild(new MovieClip());
playlist.header = new Array();
for (i=0; i<3; i++) {
playlist.header[i] = playlist.addChild(new MovieClip());
or (j=0; j<6; j++) {
[Code] .....
How would I declare the arrays within the for loop, but still access them later without them becoming undefined?
I have 26 buttons in my library named BUTNA, BUTNB, BUTNC, etc. all the way to BUTNZ.
I want the script to pick a random button from the library and place it on the stage.
I am probably doing this wrong, but I am lost.In my script, I need the variable btnp1 in place of BUTNZ in line 8.I don't know how to do this.[code]...
in as2 you used to be able to just declare a variable on a movieclip something line myMC.newvar= "something". this does not seem to work in as3 I get undefined property. Am I missing something on how to dynamically declare variables to sprites and movieclips?
View 6 RepliesI'm trying to trigger a public var which is located in an external class but can't trigger them from my Main class.[url]...
View 2 RepliesI have several movieclips that I exported to actionscript from the library (c01,c02,c03,...)In the actions I have a conditional that checks a variable and depending on the variable provided I want to create a new instance of that movieclip. For example if cityY==1 then I want to create a new c01.
I tried with conditional and with a switch/case but I get an error declaring the newCity variable more than once.[code]...
What is the difference between declaring a variable like this: variable = 1; and declaring it like this: var variable:Number = 1? Why is it better to use the second way?
View 4 RepliesIm using a tween engine, and its syntax for use is as follows::
[Code].....
How can I write "_x",100,1,"easeout",0,callback as a string?? I have tried to put "these" around the text. The problem seems to be that "_x" and "easeout" which are effectively strings inside the string! -- but for the tween engine to work - I need to declare that.
I'm trying to find information in how or if it it possible to declare a Variable Type that can accomodate 1 of 2 different Types In this particular case I'd like to set a Variable able to accept either Integrals or Strings I know i Can use a wildcard as below and it works, but it also allows for any other type to be added.
private var _destination:*;
My first Thought was something like this
private var _destination:String^int;
private var _destination:String|int;
Unfortunatly this does not work
I'm trying to create a unique variable and reference to it with myRewind for some button functions.
I'm trying to create this rewind+variable as the unique identifier but it just seems to be using myRewind as the variable and overwriting it.
Code:
//Setup subsection rollovers
function createRollover(myContainer, rollName) {
btnName = rollName+"_btn";
mcName = rollName+"_mc";
[Code]....
I've got a for loop and some fuctions working, but can't get one line of code to work. The red line below is what I'm having a hard time with. I'm calling a function called "moveit". If I insert moveit(x1, y1); then it works, and my movieclip is moved to the x and y positions that I specified for item #1. Though I want it to work for 10 items (I only have coordinates for two here, and will add the rest later).
I've searched my ActionScript book and just can't figure out what the syntax should be for calling that function.
[Code]...
I have an array like this:
Code:
var myData = new Array();
myData["name"] = "John";
myData["Age"] = 35;
What is the syntax to loop through and get the key and value? I have tried for each and for in but they just give me the value of "John" or "35", how can I get the key e.g. "Name" and "Age"?
I have put all button inside movieClip called "container" and I have added "container." inside for loop and now I am getting errors.
for (i=8; i<15; i++){
container.this["button" + btns[i].name.replace("btn","")].mouseEnabled = false;
}
I've got this loop and can't get it to work. It won't read the trace so I know the array call in my function statement is wrong but I can't see it at the moment. What am I doing wrong here? The rollover works when I write it out repetitively for the four buttons.
var btnAction:Array = new Array (oneBut, twoBut, threeBut, fourBut);
for (var i=0; i<btnAction.length; i++) {
this.menuMC.btnAction[i].onRollOver = this.menuMC.btnAction[i].onDragOver = function() {
[code].....
I am trying to send a value from one of my xml nodes (<marker>) by declaring it in a function 'showData' as a variable 'XMLMarker'. If I trace this value (XMLmarker) it returns the right data found in the node <marker> (which is 'myMarker_mc'). However, I need to tell the stage that myMarker_mc is a MovieClip...please see the 'PROBLEM' stated in the code below.
[Code]....
what I'm trying to do is access the data of several movies clips, that are inside of several other movie clips: MC1.insideMC._visible=false (which works, but isn't dynamic) but dynamically with a FOR loop. I've tried: For(bullet=1; bullet<5; bullet++){ "MC"+bullet.insideMC1._visible=false (this does not work) } Does anyone know the dot notation or another way to do this?
View 13 RepliesI've got this loop and can't get it to work. It won't read the trace so I know the array call in my function statement is wrong but I can't see it at the moment. What am I doing wrong here? The rollover works when I write it out repetitively for the four buttons.
var btnAction:Array = new Array (oneBut, twoBut, threeBut, fourBut);
for (var i=0; i<btnAction.length; i++) {
this.menuMC.btnAction[i].onRollOver = this.menuMC.btnAction[i].onDragOver = function() {
trace("anything");
}
};
It appears the same rotation for every branch. Is this not the correct way to randomize a loop?
Code:
for (var i:Number=0; i<branchAmount; i++) {
branch.graphics.lineStyle(1, 0x333333,1);
branch.graphics.moveTo(0,0);
branch.graphics.lineTo(0,-50);
branch.x=trunks.x;
branch.y=trunks.y;
branch.rotation=Math.floor(Math.random()*160)-90;
branchArray.push(branch);
addChild(branch);
}
I have a series of images loaded in via XML and assigned to "loady" movieclips. This code works fine:
Code:
_root.myMCL.loadClip(_root.myImages[0].attributes.url,_root.loady0);
_root.myMCL.loadClip(_root.myImages[1].attributes.url,_root.loady1);
_root.myMCL.loadClip(_root.myImages[2].attributes.url,_root.loady2);
_root.myMCL.loadClip(_root.myImages[3].attributes.url,_root.loady3);
[code]...
I want to replace this with a loop since I know the total amount of items (myImagesNo), but this isn't working:
Code:
for (i=0; i<_root.myImagesNo; i++) {
_root.myMCL.loadClip(_root.myImages[i].attributes.url,this["_root.loady" + i]);
}
I have a series of images loaded in via XML and assigned to "loady" movieclips. This code works fine:[code]
View 1 RepliesCan anyone tell me why the following is taking 4 seconds for Flash to execute:
_moleHoles = new Array();
var countingMoleHoles:Boolean = true;
var holeCount:int = 0;
[Code].....
There are 9 object on the stage (but this number could go up or down, that is why I'm dynamically grabbing these this way). So in my test case, this loop runs 10 times.
I have narrowed it down to something to do with the following line:
if (this['moleHole' + holeCount])
Is using dynamic (array syntax) object lookup that much of a performance hit?
The result I traced keep on coming back as the last in the list.It seems like the xmlList is not assign to different MC.
ActionScript Code:
private function levelsBG():void {
for (var i:Number=0; i<myXML.children().length(); i++) {
[code]......