Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




[F8] Loop That Defines Variables With Dynamic Name



I'm trying to define a bunch of dynamic text objects on the stage with the same value. As opposed to declaring their value one at a time I would like to do it in a loop. I thought this would be simple, but what I would expect to work doesn't. Below is an example of what I'm trying to do.
Code:
// This Workstextbox0.text = "test";textbox1.text = "test";textbox2.text = "test";// This Doesn't Workfor (var i=0; i<=2 ;i++){textbox[i].text = "test";}



FlashKit > Flash Help > Flash ActionScript
Posted on: 06-26-2008, 06:34 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

A "for Loop" That Defines A Set Of Variables
Fellow ActionScripters,

How do i set a "for loop" that defines a set of variables(var1-10)? possible?

for(i=1;i<11;i++){


//??????????? wanna define here var1-10

}

this is the only way i know how.
var1=0;
var2=0;
var3=0;
var4=0;
var5=0;
var6=0;
var7=0;
var8=0;
var9=0;
var10=0;

if one line of code in the for loop can take care of this, code will be mucho concise!

raskol

A "for Loop" That Defines A Set Of Variables
Fellow ActionScripters,

How do i set a "for loop" that defines a set of variables(var1-10)? possible?

for(i=1;i<11;i++){


//??????????? wanna define here var1-10

}

this is the only way i know how.
var1=0;
var2=0;
var3=0;
var4=0;
var5=0;
var6=0;
var7=0;
var8=0;
var9=0;
var10=0;

if one line of code in the for loop can take care of this, code will be mucho concise!

raskol

For I In Loop And Dynamic Variables
hi,
I can create dynamicly variables but how can I ge the values?
my trace action doesnt give me the values
has somebody an idea?

// <code>

var cnt = 0;
for (var i in nav_mc) {
nav_mc[i]["movie"+cnt] = cnt;
nav_mc[i].onRelease = function() {
//trace(this["movie"+cnt])
};
cnt++;
}
// <endCode>


//----------------------------------------------------
// OUTPUT WINDOW:
//----------------------------------------------------
Variable _level0.nav_mc.myClip1_mc.movie1 = 1
Variable _level0.nav_mc.myClip1_mc.onRelease = [Funktion 'onRelease']
Movieclip: Ziel="_level0.nav_mc.myClip2_mc"
Variable _level0.nav_mc.myClip2_mc.movie0 = 0
Variable _level0.nav_mc.myClip2_mc.onRelease = [Funktion 'onRelease']

[flash 4] While Loop And Dynamic Variables
Hi...

I've got a problem with some variables I use in my flash 4 (yes 4) movie.

I load a php script which returns the following: w1=hello&w2=world etc...it can go up to w250 (there is a variance)

These variables need to be used in the movie later on.
I do a while loop with the following code:

Loop While (a<=9)
Set Variable: "b" = a+1
Set Variable: "rw" = "word"&b
Set Variable: "ww" = "w"&b
Duplicate Movie Clip ("/word", rw, b)
Set Property (rw, X Position) = "10"
Set Variable: "y" = 33+(18*b)
Set Property (rw, Y Position) = y
Set Variable: "a" = a+1
Set Variable: rw&":n" = ww
End Loop

The loop goes ok but I have one problem with the line:

Set Variable: "ww" = "w"&b

when I enter

Set Variable: "ww" = w3

it shows the right content (out of variable w3, returned from the phpscript) but I can't seem to figure out the way to loop through it the way I want (as above)

Any ideas?

thx

How To Load Dynamic Variables Into Array Without For Loop
i have a bunch of variables...

snuggly1="blah";
snuggly2="blah";
snuggly3="blah";
snuggly4="blah";
snuggly5="blah";
snuggly6="blah";

ugly1="goes with blah";
ugly2="goes with blah";
ugly3="goes with blah";
ugly4="goes with blah";
ugly5="goes with blah";
ugly6="goes with blah";

which i acquired via loadvariables.. is there a tidy way to get them into arrays snuggly[0...6] with their assoatated key/values intact?

so i can access them snuggly[1] and ugly[1] so i will know the array's exact length?

i am seeking an ideal alternative to changing my source output to blahs="blah1:::blah2:::" and splitting strings to build the array..

peace, thanks, dross

Retrieve Dynamic 200 Variables From Text With For Loop
hi to every one

i have a problem i cant retriave my variables from may text .
the text content is :
coor_x_1=300&coor_y_1=300&point_name_1=bub_btn_1&p oint_url_1=http://www.google.gr&point_description_1=the google
coor_x_2=200&coor_y_2=200&point_name_2=bub_btn_2&p oint_url_2=http://www.duth.gr&point_description_2=the duth
.......
.....

and my acionscript code is :

1 var loader:URLLoader = new URLLoader();
2loader.dataFormat = URLLoaderDataFormat.VARIABLES;
3loader.addEventListener(Event.COMPLETE, loading);
4System.useCodePage = true;
5loader.load(new URLRequest("content2.txt"));
6 function loading (event:Event):void {
7for(var i:int =1 ; i>200 ; i++){
8var Xcoordinate[i]:Number = loader.data.coor_x_[i];
9var Ycoordinate[i]:Number = loader.data.coor_y_[i];
10var point_name[i]:String = loader.data.point_name_[i];
11var point_url[i]:String = loader.data.point_url_[i];
12 var point_description[i]:String = loader.data.point_description_[i];
13
14var circle[i]:Sprite = new Sprite();
15circle[i].graphics.lineStyle(2, 0x000000);
16circle[i].graphics.beginFill(0x00FFFF);
17circle[i].graphics.drawCircle(Xcoordinate1, Ycoordinate1, 27);
18circle[i].name = point_name[i] ;
19circle[i].buttonMode = true ;
20circle[i].alpha = .1;
21circle[i].addEventListener(MouseEvent.MOUSE_UP, onLink);
22function onLink(evt:MouseEvent):void {
23 var url = point_url[i]
24 navigateToURL(new URLRequest(url))
25};
26 addChild(circle[i])
27 }



the errors are :

line 8
1086: Syntax error: expecting semicolon before leftbracket. var Xcoordinate[i]:Number = loader.data.coor_x_[i];

line 9
1086: Syntax error: expecting semicolon before leftbracket.
var Ycoordinate[i]:Number = loader.data.coor_y_[i];

line10
1086: Syntax error: expecting semicolon before leftbracket.
var point_name[i]:String = loader.data.point_name_[i];

line 11
1086: Syntax error: expecting semicolon before leftbracket.
var point_url[i]:String = loader.data.point_url_[i];

line12
1086: Syntax error: expecting semicolon before leftbracket.
var point_description[i]:String = loader.data.point_description_[i];

line14
v1086: Syntax error: expecting semicolon before leftbracket.
ar circle[i]:Sprite = new Sprite();




thanks in advance

i am waiting for your answers

Use Of Variable Outside The Function That Defines It
why can't i use the variable "numOfItems" outside the function in the code i've attached below? i need to have a variable that gets it's value from the number of nodes in an xml document and used later, on the root timeline, outside the onLoad function of the xml, after it's been loaded.











Attach Code

var numOfItems:Number; //i've declared the variable as a number in the frame on my root timeline

var xml:XML = new XML() {
var nodes = this.firstChild.childNodes;
var numOfItems = nodes.length;
trace(numOfItems); //this trace works and returns the value from the xml document
};
xml.load("PSdata.xml");
trace(numOfItems); //this trace does not work, it shows as undefined
stop();

External Loaded Variable That Defines Frame Of Movieclip
I have a Movieclip with 3 Frames (One, Two, Three) and i have a txt File where i have either One, Two or Three. The swf should load the txt file and set the movieclip to the frame that it loaded from the txt file, but its not working.
Why?

My Variables Load With LoadVars...how Do I Execute A Loop To Assign Variables?
I have 52 (one for each week) duplicated MCs, a loadVars(), and variables "sermonTitle" and "airDate," which I'm trying to assign with the following:

this.airDate=_root.loadContent["airDate" + sermonDate];
this.sermonTitle=_root.loadContent["sermonTitle" + sermonDate];

which is placed in an onClipEvent (enterFrame) handler of the button which is duped . The vars load when I click Video > 2001.

The vars loaded have values named sermonTitle1, sermonTitle2, etc. and the same for airDate. The numbers attached reference the sermonDate which has already been assigned though my duplicateMovieclip loop:

num = 52;
ystart = b._y
n = 1;
while (n <= num) {
duplicateMovieClip("b", "b" + n, n);
setProperty("b" + n, _y, ystart + n*17);
this["b"+n].sermonDate = n ;
trace(this["b"+n].sermonDate);
n = n + 1;
}

I've tried attaching the assign code to the dupMovieClip loop:

num = 52;
ystart = b._y
n = 1;
while (n <= num) {
duplicateMovieClip("b", "b" + n, n);
setProperty("b" + n, _y, ystart + n*17);
this["b"+n].sermonDate = n ;
this["b"+n].airDate = "airDate" + n;
this["b"+n].sermonTitle = "sermonTitle" + n;
trace(this["b"+n].sermonDate);
n = n + 1;
}
setProperty("b", _visible, 0);

and it works - as far as assigning the correct value to the correct button, but it does not associate the loaded vars with them.

The SWF is VERY sluggish, though, which makes me think the onclipEvent is not the best way of assigning vars. I get the trace(this) showing all of the variables loading, so I know that's not the problem.


Does anyone know how to best assign these? I have been advised to use a loop for it. How would I go about executing a loop for this, as I will have navs loading in different text files - Thanks

Link to SWF:
HERE

User Defines Local Image And Add It To A Local Swf(CD) ?
I have to run flash (swf) locally, which in my case means a CD.

What I want to do is allow the user to have a browse (local) function and pick an image from his hard disk and use that image to see a flash movie (swf) with his/her selected image in it!

Then after the user watched the movie with his/her photo on it, the user should be able to send this movie in a site(upload it). then naturally the user should be able to see it online at that site as well!

So my questions are how to have a browse function that puts the selected image somewhere I would like it to and then use this image in a flash movie (that will be a game with the photo on it).

And I guess then to send it online I do not really have to publish a new swf with the image in it, I can send seperately the swf (game) and the image file to the server through php? Did i get that right?

So far I know flash 8 has a new class for browsing, but how do I take a file selected from a user locally and use it in the movie again locally? load variable can do that but I should know the name of the file selected and also be possible to even select a local file??

Basically it is for educational movie. It will run from a CD. there will be many interactive exercices. At the end of the section there will be one game that in order to make it more personal I want to allow the users to add their photo at the game. So far everything should take place locally. Then if the user desires should be able to send in a specific site the movie he/she just watched(which means with their photo in it).

ANy ideas how I do that.

Even general ideas will help!

Thank you

Loop With Variables?
Hello!

This one needs a little explanation before I can get to the question, so please bear with me.

I’m building a photo gallery/slideshow. When the movie loads, all 24 thumbnails are called into their respective movie clips by variables in the a file (pre1 through pre24). The URLs for the main images are also in the text file (full1 through full24).

What I would like to do is for this to act like a slideshow until someone clicks a button. For example, when the movie loads, I have full1 loading into the main (simply called “main”) clip. I'd like to set it so that on Frame 25 or so, it increases the count of the CURRENT movie clip so that it would do something like:

1. Get the current variable (full...something) that's in the main MC.
2. Increase the number of that MC by 1 (full+1?)
3. Go back to Frame 2 and keep going.

That way, if someone clicks on pre12, it would load full12 and stop, but when they click the "continue slideshow" button, it would go to Frame 25, load full13 and then keep going.

Obviously I want a loop of some kind but I can't quite figure out how to make the variable change the number on the end.

Any suggestions? Thanks!

Help With Variables And A Loop
/************* Re-use a loop *********************************************/

var a = new String(txtfld);//load text field into a variable
var i = a.split("");//returns the characters of a string comma delimited
var j = new Array(i[x]);x++;//makes an array from the characters in variable j

for(e=0;e<=a.length;e++){//loops mc_frames to array
gotoAndPlay(i[x])
}

/************************************************** ********

The above script is placed on a frame used to loop through mc_frames.
The cycle is activated by
"on (release) {
if (_root._currentframe()!=1){
_root.gotoAndPlay(1);
}
else
_root.gotoAndPlay(2);"
script on a button.

After the for loop cycle from the array has finished the movie returns to the first frame.
The problem is that the above script is only able to be used once.

Is there a way to reset/clear/reload the variables so I can replay the action with different text?
Would placing the script in a function help, so I can call the function with the buttons action?


************************************************** *********/

Help With Variables And The For Loop....
hi there

i am trying to load 10 images into a container:



Code:
var D1 = "05";
var D2 = "03";
var D3 = "09";
- - -
var D10 = "11";


for(j=1; j < 11; j++)

{

this['container'+i].loadMovie('images/thumb'+[D+i]+'.jpg');

}



it should load thumb05.jpg, thumb03.jpg, and so on ....i can figure out what i have done wrong ....

thank you for your help

Help With Using Variables In A For Loop
hi there

i am trying to load 10 images into a container like this:


Code:
var D1 = "05";
var D2 = "03";
var D3 = "09";
- - -
var D10 = "11";


for(j=1; j < 11; j++) {

this['container'+i].loadMovie('images/thumb'+['D'+i]+'.jpg'); }
this doesnt work, but if i put


Code:
container.loadMovie('images/thumb'+D1+'.jpg');
container.loadMovie('images/thumb'+D2+'.jpg');
this works but then i have to type it out 10 times and is not really great to update later

....i can figure out what i have done wrong and really appreaciate the help....

Variables In A Loop?help
help me with this problem. The script creates a movieclip for each image which when i click will show an image on a root movieclip..but when clicked,it outputs undefined..


Code:
addressVars= new LoadVars();
addressVars.load("http://localhost/test/flashmx_dbPassReturn.php");
addressVars.onLoad = function() {
for (i=0; i<this.n; i++){
myMC = createEmptyMovieClip("holder"+i, i);
myContainer = myMC.createEmptyMovieClip("container", 1);
myContainer.loadMovie(this["picFile"+i]);
myMC._x = (40*i);
myMC._y = (1*i);
myMC.i = i;
myMC.onPress = function (){
trace (this["picFile"+i]);
_root.screen.loadMovie(this["picFile"+i]); }
}
}
}
i think the problem is that in the onPress function, it can't define the "picFile" which i call from the database...help me please???!!!

Loop Variables
hi all ive got a simple question for you that im banging my head against my desk with.

i want to loop thorugh and set some variable to equal nothing.

ive got this:


Code:
for (i=1; i<=11; i++){
eval('trackLyrics'+i) = null;
}
butim getting this error:

Quote:




Left side of assignment operator must be variable or property.




there are 11 variables named trackLyrics1 to tracklyrics11 i just want to use a loop to make them all equal nothing - please help

For Loop With Variables?
hi,

got 6 transparent buttons, b1,b2...b6.
got 6 variables, da1, da2... da6.
6 movieclips, c1...c6. visually, they are the buttons the user sees

da1-da6 corresponds to alpha values of c1-c6 (onEnterFrame alpha fade equation).
On rollover (b1,b2 etc.) change the corresponding da, thus changing alpha.

So what should happen; if i rollover b1, all 5 other movies fade to 50, but one stays at 100. On Rollout, all 6 go back to 100.

I was able to do this, but without the for if loop. its long.
my loop for the onRollout works already, but the onRollOver wont.

here's the problem loop:
for (i=1;i<6;i++)
{_root["b"+i].onRollOver = function() //goes through each button
{
da1=da2=da3=da4=da5=a5;
//sets all da to 50
_root["da"+i]=a1;
//supposed to reset the da of one mc to 100, depending on which button is rolled over
}
}


my problem is _root["da"+i]=a1;
the bracket notation works for movieclip, but apparently not for assvariables.

so the loop should go... on rollover of b1, all the da is 50, so all mcs fade to 50. but da1 is reset to 100, so 1 clip remains unfaded.

sorry for the rather long post of a simple problem, i just want to be really clear.

thanks for suggestions!
p.s. if its still not very clear, just say i will post the rest of the code.

Assigning Dynamic Text File Variables To Variables
Ok so I know exactly how to load variables from a text file and catching these variables in a dynamic textbox to show there string content. But I wanted to work with the string in the passed variable (ie from txt file) BEFORE I display the text in the dymnic text box. I seem to be having trouble assigning the passed .txt file variable to a newly created variable in my movie, it keeps saying "Undefined" when I run a trace().

<code>
//The contents of the text file looks like this
&textxxx=This is the text withing the text variabale

//1st frame, layer 2 in main
loadVariables("text.txt", _root)

//1st frame, layer 1 (below layer 2)
_root.strText = _root.textxxx

</code>

->So why does it say strText "Undefined" !? Does flash not allow variables to be assigned to variables?

If you help that would be fantastic

Assigning Variables In A For Loop
HI,
I have a text field and i want to assign variables var1 to var6 to the text field one at a time.
So the actionscript should assign var1 to the text field and the assign var 2 and so on.
I know i can write six lines like
text = var1;
after somedelay
text = var2;
after some delay
text = var3;
and so on.

But i don't want to use that
I want to use the "for loop" for this assignment.

for ( i=1; i<=6; i++) {
text = var add i;
some delay
}

But the code doesn't work
Any help.

Is It OK To Change The Variables In A FOR Loop?
I've been trying to write some code which is driving me round the bend...! Right now I can't think straight... so, can someone tell me:

Is is OK to change the variables in a FOR loop?

i.e.

for(i = 0; i < 100; i++)
{
... do some stuff ...
if(certain condition met)
{
i = i - 5;
}
}

OK... I kinda know it's bad practice to do the above...
But... the thing is I need to the above.

I try to run the Flash program... and it just hangs... after a few seconds it flashes up an error saying "... do ya wanna stop this program?"

[It may just be that I'm creating an infinite loop because of a bug in my code, but I can't see where it could be!]

If I shouldn't be changing the inside variables of FOR loops, can someone tell me why? And why would it be OK to do the same with other loops?

If anyone can understand what I'm saying above: HELP!

Thanks.


Jam

Numbered Variables In Loop?
Hello there master scripters. I am trying to clean up the way I code AS. I am wondering is there a more efficiant way of doing the following?

Code:
if (fCall2 == "NM") {
listed.p0.item = _level0.NMTitleArray[0];
listed.p1.item = _level0.NMTitleArray[1];
listed.p2.item = _level0.NMTitleArray[2];
listed.p3.item = _level0.NMTitleArray[3];
listed.p4.item = _level0.NMTitleArray[4];
}
I was thinking it would be nice to set this up in a for loop kinda like this.
Code:
for(n=0; n<5; n++){
eval("listed.p" add n add ".item") = _level0.NMTitleArray[n];
}

But as I'm sure you know you that doesn't work... You get this... "Left side of assignment operator must be variable or property."

So my question: is there a way to do this?

What's The Scope Of FOR Loop Variables?
Can someone tell me what the scope of FOR loop variable is?

i.e. if I have for(i = 0, i < 25; i++)

What is the scope of i?

Am I not righ tin saying that i should only live for the life of the loop?

I've just spent 6 hours trying to figure out why my application won't work.

I've just been stuck on one sill function.
In the end, the problem was solved by changing the i variable in my FOR loop to something else.

The FOR loop in question in a friggin seperate independent function.

There IS NO WAY it should have interfered elsewhere.

Any feedback to the above would be appreciated.

Thanks.


OM

Load Variables With For Loop
I'm working on loading in a news section from a coldfusion page. I have it setup so Flash checks the coldfusion page for the 'id' of the news story, then a for loop will load in the variables (headline, body, etc.) for that news item. Everything eventually is put into a scrollpange.

The problem is that in the for loop Flash is looping faster than it can load in the variables. Is there a way to pause the for loop until the variables have loaded (I've tried an onLoad, but it doesn't affect the loop). I'm not an actionscript GURU so please correct me if there is a much easier way to do this.


Here's the loop:

for(i=0; i < newsArray.length; i++) {
var thisid=new LoadVars();
thisid.load("http://intriguemusic.com/voicst/shed/news/flashnews.cfm?itemid="+newsArray[i]);
thisid.onLoad = function(idload){
if(idload) {
_root.holder.headline=thisid.headline;
_root.holder.body=thisid.body;
_root.holder_y = _root.nextY;
_root.holder.attachMovie("news_item_detail", "news_item_detail" + i, 100 + i);
_root.scroller.setScrollContent(_root.holder);
_root.nextY = _root.holder._height + 10;

}
}

}

Making Variables In For Loop?
Hey

Know this is a stupid question, but I'm making a bunch of soundobjects in at for loop, and I want to name them sound1, sound2, sound3 and so on - and I want to store them in seperate MovieClilps called soundContainer1, soundContainer2....


But how do I do this?

my code:

Code:

for(i = 0; i < scaleNames.length; i++)
{
var MOVIECLIPNAME = this.createEmptyMovieClip(MOVIECLIPNAME], this.getNextHighestDepth());

var SOUNDNAME:Sound = new Sound(MOVIECLIPNAME);
}
But how do i make those names... can't just write "soundcontainer"+i??? Or "sound"+i......???

Declaring Variables Within A Loop
Hi im making a flv thumbnail preview gallery..this requires me to define a lot of netstream objects... not sure maybe my brain isnt working today but trying something like this


Code:
var noMovies:Number = 20;

for(var i:Number=0; i < noMovies; i++){
var _root["ns"+i]:NetStream = new NetStream(nc);
_root["ns"+i].setBufferTime(0.1);
}
however i get a syntax error expected '{' etc etc .. thanks in advance for your help!!

[F8] Assigning Variables In Loop
Hello,

have created an array, and am passing it thru a loop... but I can't figure out how to assign values in this array to a dynamically changing variable... I.E. I want a variable that changes and assigns the current array variable to it such as:

for (x=0; x<myarray.firstChild.childNodes.length; x++){
name[x]= my_array[x];
}


What is the correct syntax to have it so that it proceeds to offer the current value of "x" to the end of "name"?

Thanks for any advice!

Defining Variables From Within A Loop
is this possible?
in a subclass i need to define a bunch of variables like:

public var pos0:Point = new Point();
public var pos1:Point = new Point();

and so on.

the amount of vars is determined by a constant from an external source

what is the correct syntax to define those vars in a loop?
here is some bogus code

Code:
for (var i =0;i<POSITIONS;i++){
public var "pos"+i:Point = new Point();
};
this surely does not work...
any help ?

thanks!

Naming And Using Variables Via Loop
hi every body
I have a problem in naming movieClips, I want to make some movieClips via a number.
but when I create it, I can not call them.
take a look on the loadMovie line, where I write name+i. I don't know how it can understand in the loop, name1, name2 and so on...

for (i=1; i<= number; i++) {
this.createEmptyMovieClip("name"+i, this.getNextHighestDepth());
loadMovie(name+i , mc_place);
}

Incrementing Variables In A Loop
Hi,

I've tried searching and can't quite find the answer I'm looking for. I'm still transitioning to AS3, so this problem is probably related to syntax or the method is completely wrong. I understand that you can only declare a variable once, but I feel like there should be a workaround for this.

I have a bunch of radio buttons (named rb1, rb2, etc.), and want to add a listener to each one using a for loop. Here is the code I have:


ActionScript Code:
for (var i:int = 1; i<17; i++) {
 var rbName:String = "rb" + i;
 trace (rbName);
 rbName.addEventListener(MouseEvent.CLICK, rbClick);
}
 
function rbClick(e:MouseEvent):void {
 trace ("it works!");
}

I've also tried this as the last line in the loop:

ActionScript Code:
this[rbName].addEventListener(MouseEvent.CLICK, rbClick);

If I comment out the addEventListener line, it will trace all the names correctly. And if I do this outside of a loop (type the addEvent 16 times, once for each button), it works. It's just something about the loop and the variable redefining.

Thanks for the help!

Loop To Send Variables To PHP
I'm working on sending a lot of data from Flash to PHP (that will be stored in a database, although I'm not worried about that at the moment). I don't really have much experience with sending data to PHP, so most of the code I have has been taken from examples and tutorials to help me understand it.

I tried testing the code I have, which doesn't seem to work, so that is problem number one. But my main curiosity is that I will have a lot of variables that I want passed, all with the same name but incremented. I dont really know what the syntax would be to do it through a for loop. Here's the AS3 code I got:


ActionScript Code:
submit.addEventListener(MouseEvent.CLICK, sendData)
 
function sendData(evt:Event){
   
    var myData:URLRequest = new URLRequest("test.php");
    myData.method = URLRequestMethod.POST;
   
    var variables:URLVariables = new URLVariables();
    variables.tName = tName.text;
    myData.data = variables;
   
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, dataOnLoad);
    loader.load(myData);
   
}

function dataOnLoad(evt:Event){
    if(evt.target.data.writing == "Ok") {
        statusBox.text = "It worked";       
    }
    else statusBox.text = "Error!";
}

And the PHP code:


PHP Code:



<?php

$tName = $_POST['tName'];
$toSave ="tName=$tName";
$fp = fopen("test.txt", "w");
if(fwrite($fp, $toSave)) echo "writing=Ok&";
else echo "writing=Error&"
fclose($fp);
?>




By the way, this example just has one variable, but there are many (tName1, tName2, etc.). Thanks for any help and suggestions!

Accessing Variables In A Loop
Hello!

I have some 10 variables named s1, s2, s3 etc, which I want to access in a loop since I will be performing the same code on them all. So, I tried with


ActionScript Code:
for(var i:int=1;i<11;i++) {
trace(s[i]);
}

since I thought I'd seen something like that somewhere, but that didn't work so well :P Also, I wondered how I'd go about creating say 10 variables in a loop, with names like "name0, name1, name2". How would I go about this? Thanks in advance for any help!

Creating Variables Within A For Loop
I'm trying to create 10 variables in a for loop... for some reason it's not working:


Code:
public var maxAmountReqjecs:Number = 10;// defines the maximum allowed amount of reqjecs

for ( var i = 1; i <= maxAmountReqjecs; i++ ){
public var ["reqjecActor"+i]:Actor;// declare reqjecActor
}
Can someone tell me what the correct syntax looks like?

Loop Through All Variables On A Frame
Hi. I am trying to write a method to save the state of the game i am making. i am able to loop through all the movieclips and get their current frames but is there a way to loop through all the variables on the current frame (without knowing their names) and put them in an Array?

Thanks 4 any help

trigger2160

Variables Inside A For Loop
I am trying to assign the fallowing variables inside a for loop

The problem I have is declaring:
ns+i
p+i
so+i

vSound should work, I think, but I just do not know how to declare the other variables. Can someone help me please?








Attach Code

for(i=0;i<6;i++)
{
var ns1:NetStream = new NetStream(nc);
p1.attachVideo(ns1);
ns1.play(myArray[i]);
home.createEmptyMovieClip("vSound"+i, home.getNextHighestDepth());
vSound[i].attachAudio(ns1);
var so1:Sound = new Sound(vSound[i]);
so1.setVolume(0);
}

[MX] - Defining Variables In A For Loop
Greets,
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);
}

...but which actually works. There has got to be a way!

Thanks all in advance,

Steve

[FMX] Scope Of Variables In Loop?
Code:
var x:Number = 0;
var y:Number = 0;
var i:Number = 1;

while(y < 400)
{
while(x < 600)
{
this.attachMovie("hover_mc", "sq_", this.getNextHighestDepth(), {_x:x, _y:y});
x += 50;
i++;
}
y += 50;
}
i have no access to y in the (x < 600) loop... yet i gets incremented every loop... i am baffled! can anybody shed any light on this?

Variables Created With A Loop. How
Hi everybody,

I am trying to create several color Objects to affect several movieclips with setTransform using the same object. I think that is the way to go if I want to affect several movieclips with the same color variation.

I would like to use a loop for();

BUt I have no idea how to do this
...

Could you please tell me what you think?

Thanks 4 Ur help

Trouble With Variables + Loop (while)
Im a newbie to write scripts
I m trying to make a Loop using While of this information


Working no loop>>>>>>>>>>>>>>>


Code:

//variables coming from PHP

members = 2;
ramo1 = "automotivo";
pos1x = 500;
pos1y = 150;
empresa1 = "Sosokar Veículos";
meuid1 = 2;

ramo2 = "alimento";
pos2x = 330;
pos2y = 80;
empresa2 = "Super Food";
meuid2 = 1;

_root.moldura.mapa.attachMovie(ramo1, obj1, 1);
obj1._x = _pos1x;
obj1._y = _pos1y;
obj1.onRollOver = function() {
setProperty("obj1.empresa_txt", _visible, "1");
obj1.empresa_txt = empresa;
};
obj1.onRollOut = function() {
setProperty("obj1.empresa_txt", _visible, "0");
obj1.empresa_txt = "";
};
obj1.onPress = function() {
setProperty("_root.infos", _visible, "1");
_root.infos.ncliente = meuid;
_root.infos.gotoAndStop(2);
}
};

<<<<<<<<<<<<< End of Working


//---------------------------------------------------------------
Not Working and Crashing>>>>>>>>>>>>>>>

i=1;
while (i <= members){
set("_ramo"+i, eval ("ramo"+i));
set("_pos"+i+"x", eval ("pos"+i+"x"));
set("_pos"+i+"y", eval ("pos"+i+"y"));
set("_empresa"+i, eval ("empresa"+i));
set("_meuid"+i, eval ("meuid"+i));


//---------------------------------------------------------------
_root.moldura.mapa.attachMovie("ramo"+i, "obj"+i, 1);
set("obj"+i+"._x", eval ("_pos"+i+"x"));
set("obj"+i+"._y", eval ("_pos"+i+"y"));
set (btvar ,eval("obj"+i)); // I think this is wrong
btvar.onRollOver = function() {
setProperty("obj"+i+".empresa_txt", _visible, "1");
set("obj"+i+".empresa_txt", eval ("_empresa"));
}
btvar.onRollOut = function() {
setProperty("obj"+i+".empresa_txt", _visible, "0");
btvar.empresa_txt = "";
};
btvar.onPress = function() {
setProperty("_root.infos", _visible, "1");
set("_root.infos.ncliente",eval ("meuid"+i));
_root.infos.gotoAndStop(2);

i = i + 1;

} // End of While
};
<<<<<<<<<<<<< End Not Working and Crashing

Thanks all

Create Variables With Loop?
ActionScript Code:
var labels:Array = new Array("label 1", "label 2");for (var i:int = 0; i < 2; i++) {   myItem+[i] = new ContentMenuItem(labels[0]);   myItem+[i].addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doSomething);   myCustomMenu.customItems.push(myItem+[i]);  }
Possible? I want variables to end up myItem0, myItem1, etc.

[MX] - Defining Variables In A For Loop
Greets,
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);
}

...but which actually works. There has got to be a way!

Thanks all in advance,

Steve

For Loop Variables/arrays
in a for loop, I want to assign new arrays and possibly their initial value as well.. I can do the values without problem, the array name has turned out to be tricky for me.

Example:

for(i=1;i<10;i++){

myarray[i]=[this.myvariable[i]];
}

with the intent of getting

myarray1=myvariable1;
myarray2=myvariable2;
myarray3=myvariable3;

I know Im missing something, just cant think straight.

[FMX] Scope Of Variables In Loop?
Code:
var x:Number = 0;
var y:Number = 0;
var i:Number = 1;

while(y < 400)
{
while(x < 600)
{
this.attachMovie("hover_mc", "sq_", this.getNextHighestDepth(), {_x:x, _y:y});
x += 50;
i++;
}
y += 50;
}
i have no access to y in the (x < 600) loop... yet i gets incremented every loop... i am baffled! can anybody shed any light on this?

Can You Make Variables In A Loop?
I'm still kinda new to Actionscript but I'm trying to do something like this:

for (i=0; x=i; i++) {
// make a variable
var name + i = array[i];
}

Could that be done?

Thanks!

Declare Variables In A For Loop
Hi guys ... this seems quite a simple thing to do, but i can't do it!!

what i want to be able to do is create variables, one for every value in the for loop, i tried this, but it didn't work:


ActionScript Code:
for (i=5; i>=1; i--) {
    var ["varnumber" + i] = i;
}


thanks in advance

Bongo

Loop, Arrays And Variables
Last edited by phlop : 2006-07-10 at 15:34.
























Hey there, trying to put some actions on buttons that are being dynamically created in a loop.

It worked fine, until I am trying to use the String.toLowerCase(); function.

The basic of my code is as follows.
The function gets run for each in the loop.


ActionScript Code:
var myString:Array = [];
 
function myFunction(i){
  create new movie clip, move to position,
 
  movieClip[i].onRelease = function(){
myURL = "http://www.blah.com"+variable[i]+".htm";
myString[i] = myURL.toLowerCase();
getURL(myString[i]);
}
delete myURL;
}



Anyone know why this remains undefined?
When I take the toLowerCase out, it works fine...

[AS2] Problem Using Variables And For Loop
Alright: I know what I'm trying to do but seems my logic is flawed.


ActionScript Code:
//Loader information for each page.
var btnsList:Array = new Array();
btnsList.push({btnLocation:btnResKitchens, txt:"Residential Kitchens", file:"images/flash/Preview_ResKitchens.jpg", prefix:"reskit"});
btnsList.push({btnLocation:btnResEntCenters, txt:"Residential Entertainment Centers", file:"images/flash/Preview_ResEntCenters.jpg", prefix:"resent"});
btnsList.push({btnLocation:btnResMantels, txt:"Residential Mantels", file:"images/flash/Preview_ResMantels.jpg", prefix:"resmantel"});
//End Loader information
 
for (var i:Number = 0; i<btnsList.length; i++) {
    //trace(btnsList[i]["file"]);
    btnsList[i]["btnLocation"].onRollOver = function():Void {
        //_level0.prevLoader.loadClip(btnsList[i]["file"], 25);
        trace(btnsList[i]["file"]);
    }
}


Basically I'm trying use an array to control all properties of different buttons I have... what text to set a text field, where the accompanying file is located, etc, etc...

Problem is, I cant get the current iteration of the variable "i" from the for loop to transfer to the .onRollOver function. All buttons trace "undefined" when rolled over. (because "i" equals 3 now and there is no 4th element in the array).

Any help?

Declaring Variables In Loop
Hello, I am wondering how to declare a variable inside a event handler which will change it's name automatically. I want the name to increment after ever time a new instance is made. My Code is as follows:

Code:

function addLight(E:TimerEvent) {
var 'l' + num:Light = new Light();
num++;
}



where num is a variable set at 0 so i would like there to be instances of this object like l0, l1, l2, l3.
Any ideas anyone as to how i can solve this problem? Thanks

With, TellTarget, Named Variables In A Loop
Okay, here's the scenario:

MC named "Object#"
inside that, there is MC "BRICK" with 30 frames, each frame with a different image.

There are 30 instances of "Object#", named Object1 through Object30. Now, I have a function that creates the instances, and names them (Object1, Object2, etc...). But when I try this:

for($i=1; $i<=30; $i++{
Object$i.BRICK.gotoAndPlay($i);
}

Failure. I've also tried With:

for($i=1; $i<=30; $i++{
with(Object$i.BRICK){
gotoAndPlay($i);
}
}

and, tellTarget:

for($i=1; $i<=30; $i++{
tellTarget("Object" + $i + ".BRICK"){
gotoAndPlay($i);
}
}

It doesn't seem to allow me to use a variable to specify a named instance to control. Can anyone help me solve this? I don't want to have to make a function that sets all 30 instances manually! Talk about a maintenance headache!

Thanks in advance to all you Guru's out there!

Creating Year Variables With A Loop?
Hello,

I need to create varaibles from 1995 to the Current Year. Of course I know how to create the vars like:
Var1 = 1995
Var2 = 1996
Etc...

But after building this I do not want to have to update the code ever year. So, can anyone tell me how to declare the vars with a loop upto the current year??

Thanks

Copyright © 2005-08 www.BigResource.com, All rights reserved