ActionScript 2.0 :: [FMX] Scope Of Variables In Loop?
Apr 11, 2005Code:
var x:Number = 0;
var y:Number = 0;
var i:Number = 1;
[Code]....
i have no access to y in the (x < 600) loop... yet i gets incremented every loop.
Code:
var x:Number = 0;
var y:Number = 0;
var i:Number = 1;
[Code]....
i have no access to y in the (x < 600) loop... yet i gets incremented every loop.
A question about the variable within the for loop it is always stuck on False -- even if the first condition gets achieved.I read that the for loop variable is treated as if it is completely seperate varibale from the one in the main even if they have the same name
PHP Code:
canwalk = true;function isheblocked [code]..........
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code in Flash will throw an error:
[Code]...
but it won`t throw an error in Flex (only warning in Editor). Why?.2. How Flash sees variables in loops? Apparently this:
[Code]....
isn`t equal to just: var mc:MovieClip=new MovieClip(); var mc:MovieClip=new MovieClip(); because it will throw an error again as earlier in Flash, but in Flex in function not? Is Flash changing somehow my loop before compilation?
.3. Where in a class in equivalent to timeline in Flash - where in class I would put code which I put normally on timeline (I assume it is not constructor because of what I have written earlier, or maybe it`s a matter of Flash/Flex compiler)?
[Code]....
I was just wondering what the new method for creating global functions and variables are - the _global method has been taken out of as3
View 1 RepliesI have a simple object defined by an object literal, and have a couple functions assigned to this object. Inside the functions, I try to access global variables, and it only gets undefined. The Flex debugger tells me the variables are just right up the scope tree.Yes, I know I can access Thing by using 'this', that doesn't solve my scope issue though.Project Flex Compiler Settings: Flex SDK 3.4, Require Flash Player 10.x.Example:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="Thing.bling();">
<mx:Script>
<![CDATA[
[code].....
I add this actionscript code on the first frame. Variables are loaded but. The question is below the code.
[Code]...
I have a Debug class I've written, and I'd like to include a static trace() method in there, unfortunately I have no idea how to then access global / top level trace as effectively I've blocked it with the local static scope.[code]
View 4 RepliesHow 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.
View 5 RepliesSay, I had a loop in a function...
[Code]....
How would I refer to a in another function
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? { ...
[code].....
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.
[Code]...
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 need to make new sprites on-the-fly within a for loop, and this code does not work:
Code:
for(var i:int = 0; i<5; i++) {
var this['menuBtn'+i] = new Sprite();
[code].....
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)
[Code]...
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".
this VERY long, redundant code works:
Code:
magicBox_mc.allClips_mc.n1.image1.source = "newsClips/images/newscast01.jpg";
magicBox_mc.allClips_mc.n2.image2.source = "newsClips/images/newscast02.jpg";
magicBox_mc.allClips_mc.n3.image3.source = "newsClips/images/newscast03.jpg";
magicBox_mc.allClips_mc.n4.image4.source = "newsClips/images/newscast04.jpg";
[Code]....
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;
Here's what I've got:
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've a .txt-file containing variables. The variables are structured like this:
aaa_301, bbb_301, ccc_301
aaa_302, bbb_302, ccc_302
...
[code]....
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?
View 1 RepliesI 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;
}
Here's what I've got:
[Code]...
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?
[Code]...
i wanna create a photo album.this is thumbs page.
Code:
for(i=0;i<2;i++){
this.createEmptyMovieClip("logo_mc"+i+"", 999);
loadMovie(""+i+".jpg", logo_mc+i+);
}
how can i solve this problem about variables??
The plan is to set up variables to react to a flashvars value like this:
[Code]...
There would be many mainVars (over 100, actually) and this setup isn't working.
want to make this stuff working.
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 =
[code]....
The plan is to set up variables to react to a flashvars value like this:[code=html]<param name="flashvars" value="mainVars=1" />[/code]
[Code]...
There would be many mainVars (over 100, actually) and this setup isn't working.
I'm using a few for() loops to populate my game. Now, I have 2 versions of each function, one that executes when my variable "debug" exists, and the other that activates only if "debug" does not exist.Looks kinda like this:
ActionScript Code:
// first, if debug exists, the script will execute for the single instance of my movie clip "myBox_0".
if(debug){
// assign a value to the string "myTarget"
[code]....
Now, on the line I starred*, if I enter "images/0" instead of what you read there, then it works. But when I try to use the variable "i" then it gives me the error "Error opening URL 'images/undefined.png'" I ran a trace statement to track "i" through the code and it works up until I enter the tellTarget statement... how can I get my script to pass that variable through that statement?
i want to query about a point here,
Now, When i make a loop for example a "for" loop
ActionScript Code:
var i:int;
for (i=0;i<4;i++){
// Looping Code For 4 Times
}
in the looping code, when i use a variable, for example "myVar"
Can i make the variable name be "myVar0" in the first time looping, and the name be "myVar1" in the second time looping, and so on ..
Is there a way to make the variables generated from a for loop within a function accessible to other functions? because at the moment other functions are firing errors because the variables refferenced are from a different function.
You may of seen this code from other threads
ActionScript Code:
function nodePoints():void {
//VarName, mcName, XPos, YPos
var row1:Array = ["clientComp", new clientComp(), 100, 200];
[Code]....