Actionscript 3 :: Getting The Right Variables In A Foreach Loop?
Dec 20, 2011
I'm trying to get specific variables out of a for each loop. These variables are used to display a click event on a marker on a map. If you click the marker on the map, the details pop over it. Now these details are being overwritten each time the loop starts (50 times). The solution I'm looking for, let's me select a marker on the map with the according detail attached to it.
There might be an easy solution but I haven't found it yet.
The code : for each(artistXML in artistList.events.event)
How can I make a bunch of variables from a for loop. for example for (var i=0; i<total; i++) {var bunch(i);}. that i make a bunch of variables named bunch1, bunch2, bunch3. I keep getting errors. I program and use so many different languages that I dont know if that can be done with AS3. my only other alternative i can think of is to create some sort of event dispatcher object array. but I dont know how to get them all to send events to one listener with there index number.
I have a file with a many button instances, the names of which I've put into 2 different arrays. I'm adding an eventListener to each button dynamically using the forEach...in method. I want the buttons in the first array to call a function and the buttons in the second array to call a different function. I'm getting no errors on compilation, but my problem is that buttons in both arrays are calling both functions.
I got a europe map designed in flash (1 movieclip, 1 frame, really simple), which contains the map as drawing objects directly inside the scene and in addition some specific countries as clickable buttons. So far it's working fine. What I need now is to make all the other drawing objects clickable without having to edit and script each object. I'm thinking about something like this (pseudo code):
I have an image slideshow program working right now and it takes in a folder of a hard coded in number of images. I would like to change this so that it can take in a folder and will display all of them no matter the number. Is there a way to do this in flash? I'm thinking something like the foreach loop in perl or other scripting language. It is possible to store then number of images in a text file but I also don't know how to read that in flash either. I'm working in actionscript 3.
Is it possible to use a for loop to "combine" array variables..g.
Actionscript Code: var myArray1:Array = [1, 2, 3]; var myArray2:Array = [1, 2, 3]; for (var i:Number in myArray1 && var i:Number in myArray2) //is something like this possible? { ...
How am i to get the variables zombData.zomb0, & zombData.zomb1 from inside the "for loop"
I want this trace command dynamic
Quote: trace(zombData.zomb+i);
it works when i put zombData.zomb0 (a variable sent from a PHP script)but if i want to make it dynamic how it is; It fails & outputs NaN How do i make it dynamic for the loop?[code]...
I have 24 movie clip buttons. Named "btn1" through "btn24". I can't figure out how to return the variable as a number that cooresponds to each button onRollOver.
i'm trying to use a for loop to generate for me a set of vars, but it's not really working out. =.=.
I'm loading the image file names from a xml, and i want that the for loop create vars like "fotoToLoad0, fotoToLoad1 ..." and load the filename within.
I guessed i had to use the eval command, but as far as my ignorance sees it, when it is used, the eval makes a variable reffer to another and not fill it's value. (I guess i'm wrong thou).
Here's what i've tried so far:
Code: for (i=0; i< totalNodes; i++){ var fotoEnd = imagesXML.firstChild.childNodes[i].firstChild.firstChild; var fotoTemp = eval ('fotoToLoad'+i); fotoTemp = fotoEnd;
That's quite not working thou =(. If i try used 'fotoToLoad1" for example, in a text box it just returns undefined
I used to dynamically set some variables using a FOR loop kinda like so PHP Code:
//Sorry, from memory var possibleValues:Array = ["red","green","blue","yellow"]; for (i=0;i<possibleValues._length;i++){ _root["colorNumber"+i] = possibleValues[i]; }
Second question, using that code in a function would set the variables at the root level making them available throughout the timeline. Without "_root" how do I get that variable available to everything?
i'm having trouble creating an image preloader with a loop. my apologies, this might be a very simple task that i've been pulling my hair out over for an hour.
i have 8 UIloaders. each named image1,image2,image3, etc. they are inside a movie clip called "allClips_mc".
ActionScript Code: var val1:Number = 10.80; var val2:Number = 11.54; var val3:Number = 12.22; How would I express this in a loop? var sum:Number = val1 + val2 + val3;
var cColor1:Color = new Color(mcBut1.mcFill); var cColor2:Color = new Color(mcBut2.mcFill); var cColor3:Color = new Color(mcBut3.mcFill); var cColor4:Color = new Color(mcBut4.mcFill); var cColor5:Color = new Color(mcBut5.mcFill);
What I'd like to do is write a loop to handle all that code in less code. So, how do I define variables using variables?
Something like:
for (var i:Number = 1; i < 6, i++) { var cColor+i = new Color(eval("mcBut"+i).mcFill); }
i'm trying to create a menu system where each item expands in height when clicked but is then collapsed back to the original state when other items are clicked.m is the height of the expanded state. n is the height of the collapsed state. i is the number tacked on the instance name.Also, I'm using Tweener for smoother transitions. I've done this already by copying out the code but it's 24 items so 24x24 lines of code when I'd like to be able to do it a little more elegantly. Here's roughly what I want to do, but don't know if it's possible:[code]So every box below the one that's been clicked on most recently gets the value of m added to the y value and every box above doesn't.Is it possible to retrieve the value of the variable i that corresponds to the currentTarget?
Actionscript Code: for (var i:Number=1; i<=3;i++){ var char_name+i = event.target.data.char_name_ + i;//It should be like//var char_name1 = event.target.data.char_name_1;//var char_name2 =