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








Dynamic Instance/Variable Names In Loops


This has been bugging me for a while but I'll have a series of movieclips, variables, input boxes, or whatever with a name then a number as their names. For example input0, input1, input2, etc. In AS2 I could throw them into a loop like so:


Code:
for(i = 0; i<3; i++)
{
this["input"+i].text = array[i];
}
...or something to that regard. How do I do this in AS3 where I can set up a loop and dynamically call the numbered instance name?




FlashKit > Flash Help > Actionscript 3.0
Posted on: 10-27-2008, 02:21 PM


View Complete Forum Thread with Replies

Sponsored Links:

Accessing Dynamic Instance And Variable Names
Version: Macromedia Flash MX Professional 2004

1) I am trying to access certain instances in my flash game that change depending on certain things. Here is an example that I tried:

Works (static case):
_root.projectile1._x = currentGunX;

Doesn't Work (dynamic case):
_root.["projectile" + zLevel]._x = currentGunX;

Only to find out that the creation of the dynamic instance name with ["projectile" + zLevel] does no work in my newer version, so I need help with how to access the dynamic instance.

2) Secondly, I have a variable that I want to access in basically the same case, here it is as a static case:

Works (static case):
currentGunX = _root.controller.GUN1_X;
Doesn't Work (dynamic case):
currentGunX = _root.controller.["GUN" + controller.activeGun + "_X"];

So, all in all, I need the way to dynamically access both instances and variables. Any help is appreciated.

View Replies !    View Related
Loops And Instance Names
Hi,
new to as 3.0 I am surprised that, if you generate movieclips or sprites, or in this case loaders, by using a loop, the instance names are not instance1, instance2, instance3, but instance 1, instance3, instance5 et cetera. Why is this?

It makes it kinda hard to use instance names to, for instance, load the right pic in the loadPic function. I guess I need to find out what the index of the clicked instance is, but how?


Code:
for (var i=1; i<6; i++)
{
var picRequest:URLRequest=new URLRequest("pics/t"+i+".jpg");
var picLoader:Loader= new Loader();
picLoader.load (picRequest);
picLoader.x=i*50;
picLoader.y=60;
picLoader.addEventListener (MouseEvent.CLICK, loadPic);
addChild (picLoader);

}
function loadPic (event:MouseEvent) {

trace (event.target.name);//output instance1, or instance3
//et cetera.
//how can I get the index of the instance here?

}
Many thanks,

JerryJ.

View Replies !    View Related
For Loops With Variable Names
im sure iv done this before but cant remember how

i have a shared object with 25 pieces of data but for now ill just use 4 cell1, cell2, cell3 cell4.

initially each cell will have the same value (ie false) rather than hardcoding each cells content i want to use a for loop to enter the values.

something like this

for (i=0; i>3; i++) {
so.data.cell1 = false;
}

how do use the 'i' value to increase the cell number each time it loops. i thought something like
so.data.cell+i
but as soon as i did it i realised it wouldnt work and why.

please help

View Replies !    View Related
Variable Instance Names
In a menu header I'm making for a site, I want it to import a text file that has each menu item and link URL, then create MC buttons for each of them and distribute them evenly across a certain y value with certain endpoints.

Anyway, I'm getting started on the code to read the text file and create the MC's. To save myself the hassle, I will put the number of links as the first var in the imported text file. I make a for statement, counting up from 1 until it has reached the total number of links, and want to make an MC for each one. So, I createBlankMovieClip, using "linkname_"+i to create it using the current iteration of the for statement. However, how do I call that to add a text field to it?

linkname_+i.createTextField() doesn't seem to work.

View Replies !    View Related
Variable Instance Names?
Hi. Can I address a movie clip with a variable?

For example I want to use a variable called "counter" to be used when addressing a movie clip


The movie clips instance names will be in the properties panel
Entry1
Entry2
Entry3

Can i address "Entry" + the counter variable in some way to end up addressing Entry1, 2, or 3

View Replies !    View Related
Making A Instance Names Variable
Ok, so I want to have my flash app dynamically create movie clips using the duplicateMC command and then change the contents of each movie clip (ie mc1.textvar="ABC" mc2.textvar="XYZ").

I have no probs if I hardcode the number of movie clips, but I want to make it dynamic (will be setting variables outside of flash)

Attached to a button in the root level I want to do something like

for i=1 to NumMoviesVar
myclipTemplat.duplicatemovieclip("myclip"+i,1);
myclip[i].textvar="This is clip" + i
next

Another button would then go through and hide all of the dynamically created movie clips.

Is there any way I can reference the instance name in a "variable" sort of way with this pseudo array? Or is there a better way?

TIA
-Rob

View Replies !    View Related
Putting Instance Names Into A Variable
Hello All. Can you put instance names into a variable? I have a bunch of MC's and would like to set a variable to group them all together so I can tell them all in one shot to go to a specific frame without haveing to tell them all separetly. Say I have 5 mcs with instance names of player1,player2,player3.player3,player4. I would think you could set a variable by saying players=player1,player2,player3.player3,player4 and then with a button say on press players gotAndStop(1)

doesnt work though what am I doing wrong?

View Replies !    View Related
Trouble With Variable Instance Names
Hi

I attached a movie to the root:

Code:
_root.attachMovie("myMovie", "movie" + i, i);


now, I can access this clip's properties like this:

Code:
_root["movie" + i]._x = 100;


what I did then, was to create a new textfield INSIDE this attached movieclip:

Code:
_root["movie" + i].createTextField("text" + i, i + 100, 2, 2, 96, 16);


HOW DO I ACCESS THIS TEXTFIELD, NOW? This doesn't work:

Code:
_root["movie" + i]["text" + i].text = "Hello";


Please help...

View Replies !    View Related
Problem Constructinmg Variable And Instance Names
I have several dynamic text fields. They are named : "field_0", "field_1", "field_2" etc.. Also I have several variables called
"var_0" , "var_1", "var_2" etc.

I tried something like this:
for (i;i<3;i++){
_root.field_+i+.text=var_+i;
}

+ sign does not work. How do I construct the variable names and instance names using "i" within the for -loop?

View Replies !    View Related
Understanding Variable References Vs. Instance Names
Hi all - while i've been workginw ith AS3 successfully for a little while now, there is a concept I don't quite understand, and as an instructor I'd like to field this question if it comes up. I'm trying to understand the difference between a variable used to store a reference to a display object, (ie. a dynamically attached movieclip), vs. the instance name (as represented by the name property). I noticed that tracing a dynamically created instance will usually output a name such as 'instance2', or something like that. I am still able to assign a name using the name property. Example:

var mc:LibraryClip = new LibraryClip();
addChild(mc).
//I can now control this instance using 'mc'
mc.name = "myClip";
//Now it has an instance name which I can also use

- which is the proper/preferred way to control dynamically composed instances - by the var ref or the name? Also, how do you overcome issues when using a loop to create multiple instances (it seems to not care if you use the same name at every loop):

Example:
for(i=0;i<10;i++) {
var mc:LibraryClip = new LibraryClip();
addChild(mc).
}

Thanks, as always.

View Replies !    View Related
Do I Just Cut And Paste, And Change Instance And Variable Names
I like the reflection in Amen's photo gallery code, and I like the scrolling thumbnail panel in Dale's code. Both allow modification. And, the links to the files are:

Amen's: http://www.actionscript.org/resource...ial/Page1.html

Dale's: http://www.blog.noponies.com/archives/16

I think I should try to modify Amen's, as it is more like I want. Do you agree that it's the most practical decision?

How do I simply take out the hyperlinks ( 1, 2, 3) buttons in Amen's gallery and put in (replace it with) Dale's scrolling thumbnail panel. It is confusing to me to figure out how to modify Amen's code because of all the files at my finger tips. For instance, Amen uses one AS3 file, an apparent blank Flash CS3 Document (which my have a document class?) with the same name as th AS3 file name, an xml file, and an images folder. Dale uses a Flash CS3 Document, a gs folder with TweenLite and TweenFilterLite AS3 files, two XML files, a CSS file, a thumbs folder, a large pictures folder, and a fonts folder.

Of course, I plan to add my own pictures and background changes afterwards.

If you paste or attach code and brief instructions or explanations, it would be greatly appreciated.

yours sincerely






























Edited: 07/19/2008 at 06:03:49 AM by jntSpecialty

View Replies !    View Related
Variable Instance Names For Text Fields?
I am wondering if it possible to create a unknown number of objects and give them instance names using variables and then refer to them using other variables. For example, create n text fields named field_1 through field_n and then assign text to them somehow using field_var. I'm trying to make a calendar that displays the current month based on system time, though I can think of a great many other uses for this kind of thing. I'm just not at all sure how to go about doing this or if it is even possible. It seems as though it should be. If this isn't clear enough let me know and I shall try to explain myself a bit better. I was able to do the following but there were issues:


Code:

for (i=1;i<31;i++)
{
this.createTextField("date"+i+"_txt",1,thisX,thisY, 50, 50);
}



The first problem I have with this is that later on I cannot do this:


Code:

datei_txt.text="whatever";



and to boot, when I ran the debugger it turns out it doesn't create 30 instances, it just keeps destroying the previous one and replaceing it with the new so that at the end I only have one field with an instance name of date30_txt.

So how can I create this effect in a different manner?

Thanks in advance,
~NH

[edit] I had another though aswell, createing an array of text fields, but I can't figure out how to create a text field within one element of an array object so that I can refference them through the array's index.

View Replies !    View Related
Loops, Combine String With A Variable, Instance Name (mc)
Ello,
First of all, great forum ..

I'm quite new to actionscript, do have experience in java (js) and quite a lot with php, but actionscript? nope ..

I have to do this little project, and I wanted to use a loop for a hitTest for not running thru walls ..

I'm using a walls as a mc with an instance name and then test inside the object that's not suppose to run thru it to do a hitTest that equals the instance name of the wall mc like this;


Code:
(this.hitTest(_root.verticalLeft1))
Now I'm copying this code for all the other walls, verticalLeft2, verticalLeft3, ..4, also using horizontalTop1, horizontalTop2, ..3, etc etc ...

I was planning to use a loop so i don't have to copy it 20(x4) times, like this


Code:
for(var i:Number = 1; i<20; i++) {
var wallName = eval("verticalLeft" + i);
if (this.hitTest(_root.wallName)) { _x = _x+1; speed = 0; }
}
Now, the way I was thinking is that while looping, the wallName should be verticalLeft1, verticalLeft2, 3 etc .. identical to the mc with her instance name .. but it doesn't work .. obviously cause I don't know how else it should work .. Am I not suppose to use a String here? or at all, is it a String? cause var wallName:String = eval("verticalLeft" + i); doesn't work either .. or is eval(); totally wrong? .. pfff i've lost it

in PHP it would be something like ${"verticalLeft".i} .. but it's not php is it!

Well.. any help would be appreciated .. thanks ..

View Replies !    View Related
Dynamic Instance Names
Hi Everyone,

Well, I've been racking my brain on this one now for a couple of hours. I know I'm being an idiot but it's just not coming to me.

What I hoping to do is this. I have six movie clips, with six instance names, screen1, screen2, screen3 etc.

I want to be able to get properties from these movie clips, but I want to be able to create code dynamically. What I mean is I want to write something like:

(screen & x)._y = a;

where x is a variable... thus creating:

screen1._y = a;

hope that makes sense.. anyways.. for the life of me I can't get the syntax right, and now I'm starting to go batty!!

anyways.. any help what so ever would be most appreciated. Thanks in advance.

Pat

View Replies !    View Related
Dynamic Instance Names.
Hey guys,

Hope you can help me...

What Ive made in a movieclip (imageMC1) which just checks a variable and loads a jpg then stops.

I want to be able to duplicate this clip over and over with an incrementing instance name.

This is the code I have (which obviously isnt working).

Any suggestions would rock. Thanks!

x=x+1;

if(x > totalImages){
x=1;
}

_root.loadImage = x + ".jpg";

thisMC = "imageMC" + (x-1);
nextMC = "imageMC" + x

duplicateMovieClip('thisMC', 'nextMC', x)

View Replies !    View Related
Dynamic Instance Names
I need to use attachMovie clip feature to my mainSWF. the problem i have is how to label instance names of the buttons that will be duplicated, so i can then assign a new set of commands.

rat

View Replies !    View Related
Dynamic Instance Names?
say i want to put 30 instances of the ball movieclip on the stage and i want to name them ball1 ball2 ball3 ball4 with a for loop.. how would i do that.... i don't even really know what to call it.. dynamic instance variable names?

thanks in advance.

View Replies !    View Related
Dynamic Instance Names
Hey guys,

How can I get this working properly? I cant seem to figure out how to set a dynamic instance of a movieClip with a variable in its name, then reach it...

Thanks!


Code:
var ["feedTextTemp"+i] = new feedTemplate_mc();
holder_mc.content.addChild(["feedTextTemp"+i]);

["feedTextTemp"+objRef.feedid.id].setText(objRef.literal._label + " <b>" + objRef.user1._label + "</b>");

View Replies !    View Related
Dynamic Instance Names
I am creating a migration map that is shaded, etc depending on info from an XML file which I can get to load perfectly. However, after that, I don't know WHAT to do so I can't research HOW to do it.

If I return let's say 21 countries from the XML, I need to dynically create 21 instances of a MovieClip. If I run a while "items exist" loop, I can trace each name. What I want to do is to create a dynamic instance name -- i.e., ttFrance, ttIreland, ttSpain when the XML holds records of France, Ireland, and Spain.

Concatenating isn't working. I tried
var "tt"+theXMLData.migration[ctr].title:ToolTip = new ToolTip(); and the compiler didn't like it. I have the linkage correct.

Please point me in the right direction.

Jon

View Replies !    View Related
Dynamic Instance Names
Is it possible to dynamically generate an instance name for an MC and use that name.

EG.

I have a text file with 5 names for buttons that I am going to use. Each button calls some more text from the same text file.

Text File:

has a variable name called 'about'.
it also has some text that will go in a text field in an MC.

But say I want to change the button to 'profile'

Is it possible, or am I just being confusing?

View Replies !    View Related
Dynamic Instance Names..can It Be Done?
hi, I was wondering how I would go about creating 100 copies of an object and then assign them all instance names depending on the position in a grid so I can assign them properties from an array.

The result is to be that of a close up of an old 4 bit green display that would display the contents of a 2D array = to the grid in size.

I have tryed many way to achive this result, but this seems to be the easyest, to get what I need, but i just dont know where to start. I can not find much info on instance names other than how to set them with the properties pannal.

I have attached a basic version of the code.

View Replies !    View Related
Dynamic Object Instance Names?
how would i go about creating dynamic instance names for objects?

here is a function i'm trying to use:

Code:
function create_myMc(my_mc_content:String, this_mc:String, this_depth:Number) {
this.createEmptyMovieClip(this_mc, this_depth);
var myLoader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myLoader.addListener(myListener);
myListener.onLoadInit = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
// add mc to array
};
myListener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
// update bytes loaded in array
};
myListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
// remove mc from array
};
myLoader.loadClip (my_mc_content, eval(this_mc));
}
only problem is i need to make myLoader and myListener into unique names for each time the function is called.
ie myLoader_1, myListener_1 and myLoader_2, myListener_2 etc etc..

any ideas?

thanks in advance

View Replies !    View Related
Creating Dynamic Instance Names
Hi,

I have a mc called "qu" on the stage which contains text boxes with instance names q1,q2...q10 and a1,a2...a10. I want to target these boxes from the main time line. However, rather than just targeting each individually from the maintime line like this

q1._visible = false

i want to target them dynamically using a counter from the maintime line. ie:

question = this["q"+i]
qu.question._visible = false

This does not work. However when i apply the following code inside the qu mc rather than the maintime line it does work:
this["q"+i]._visible = false

I hope this is clear what im talking about. can anyone help me to target these text boxes from the main time line properly?
thanks
john

View Replies !    View Related
How Do I Make Dynamic Instance Names?
In as3 i normally do:

var something:Customclass = new Customclass(params)
addchild(something)

Now i am asking how do i create/name "something" dynamically? Meaning, say use a loop to create, something_0, something_1,........something_9 etc!

View Replies !    View Related
Dynamic Class Instance Names....
I'm trying to build a controller class that creates instances of other classes. I'm new to AS 2.0 and I can't seem to figure out how to dynamically create instance names without getting a compiler error. For instance, the following code throws back a syntax error:


Code:
class Controller {
private var i:Number;
public function createButtons() {
var buttons:Array = new Array();
for (i=0; i<32; ++i) {
var button[i]:Buttons = new Buttons(); // trying to create instances of the "Buttons" class
}
}
}
So... in what way would I create instances of classes dynamically? I just can't wrap my brain around it. Any help would be greatly appreciated.

View Replies !    View Related
Dynamic Iterate Instance Names..
I always have these problems. The following doesn`t work:


Code:
for (i=0; i<=10; i++) {
table[ans+i].text = "";
}
table.ans1, table.ans2 etc are just input-text fields that i want to clear. How do i do this is the syntax wrong?

View Replies !    View Related
[Flash 8] Dynamic Instance Names
Hi, I am doing a school project (a timeline) involving 5 individual timelines ("soc_time", "tech_time", "env_time", "eco_time", "pol_time") on a single, main timeline ("timeline") that moves with the left and right cursor keys. "Timeline" has lines at 200 pixel intervals for reference (10 years = 200 pixels). There are 5 thumbnails at the bottom ("soc_thumb", "tech_thumb", etc.) and when you click on one, it makes the sub-timeline ("soc_time", "tech_time", etc) appear using timeline.attachMovie (i.e. when you click on "society" at the bottom the society timeline ("soc_time") appears on the main timeline). Inside each sub-timeline ("soc_time", etc.) there are dates ("soc_1900", "soc_1904", etc) (no attachMovie involved here, they are already in the sub-timeline). When you click on these dates, a window pops up with more information on that date ("win_soc_1900", etc)

What I need to do is simplify/cleanup my code, because now it is over 750 lines, and I know there is a way to make it shorter. Ultimately, my best idea involves writing a function that takes "soc_1900"'s, "soc_1904"'s, etc.'s _x position relative to the sub-timeline it is nested in ("soc_time"). I want to take the _x positions, divide by 20 and add 1900 which would give me the date it is.

What I have now is this:

Code:
_root.onMouseDown = function() {
if (timeline.soc_time.soc_1900.hitTest(_xmouse, _ymouse, true) && !window_soc_1900) {
_root.attachMovie("_win_soc_1900", "win_soc_1900", 101);
window_soc_1900 = true;
setProperty(win_soc_1900, _x, 85);
setProperty(win_soc_1900, _y, 95);
setProperty(this, _alpha, 80);
}
if (timeline.soc_time.soc_1913.hitTest(_xmouse, _ymouse, true) && !window_soc_1913) {
_root.attachMovie("_win_soc_1913", "win_soc_1913", 102);
window_soc_1913 = true;
setProperty(win_soc_1913, _x, 85);
setProperty(win_soc_1913, _y, 95);
setProperty(this, _alpha, 80);
}
};
//ad infinitum
As I said, this works fine, but what I want to do is something like this:


Code:
var windows:Boolean = false;
function socClick() {
if (this.hitTest(_xmouse, _ymouse, true) && !windows) {
_root.attachMovie("_win_soc"+this._x/20+1900, "win_soc_"+this._x/20+1900, getNextHighestDepth());
windows = true;
setProperty("win_soc_"+this._x/20+1900, _x, 85);
setProperty("win_soc_"+this._x/20+1900, _y, 95);
setProperty("win_soc_"+this._x/20+1900, _alpha, 80);

}
};
_root.soc_1900.onMouseDown=socClick();
I just can't get this to work, hence this thread.


Working on uploading an swf.

View Replies !    View Related
Passing Dynamic Instance Names In 1 Param
I am trying to pass a MC target to a function through one parameter... The problem is that there are multiple variables that are requiered to reference the MC properly.

is there a way to conjugate all my variables and pass the target reference to my function in one param? If so, how does it need to be sent to the function and how does it need to be reference from the function to an actual MC.

Thanks

View Replies !    View Related
Instance Names...changing...or Addressing Txt Field Instance Based On Instance Of Mc
i'm creating a mail form, that has a text effect which displays the type of info to be entered in each input box. To create this effect, i had to assign the variable name txt to the input boxes as well as the instance name txtBox. each of these text fields is contained within a movieclip, each with a unique instance name. what i need to do, is somehow assign a value/variable to each text field to pass to PHP to generate an email. I have always used components for contact forms so i'm not sure how to make the switch, AND.. the script i use for my contact form is an EXTERNAL AS file. (i use a customized version of a contact form from www.actionscript-toolbox.com [which apparently is no longer Flash related site])

ok.. this is hard to explain..... so bear with me....
If my original mail form component instance names were: tiName, tiEmail, tiSubject and taMsg (ti for textInput and ta for textArea)
and my current instance names for the mc's which CONTAIN the input boxes (with txtBox textfield instance inside them) are: name_txt, email_txt, subject_txt & comments_txt...

how would i pass/convert the users input text in each movieclip's txtBox, into the original instance name for my mail form so i can continue to use the form/PHP i have been using??

OR....

how do i take the values input by the user in each txtBox (i.e name_txt.txtBox.insertedTextFromUser or name_txt.txt, email_txt.txtBox.insertedTextFromUser or email_txt.txt) and send them to a new PHP script to send mail??

please keep in mind i am PHP retarded... hence why i re-use the same form over and over..

thanks in advance for any help. it's greatly appreciated...

if you're confused about my problem, please let me know... i'm having a difficult time explaining....

View Replies !    View Related
Flash Player 5 Discrepency With Instance Names In Mc's & Dynamic Text?
ok, i have a movieClip with the instance name "content" within it I have a dynamic text field with the instance of news_txt which calls for an outside .txt document for its content, but when I try to publish the swf it gives me an error saying:

WARNING: This movie uses features that are not supported in the Flash 5 player
Symbol=content, layer=content, frame=1:Flash MX Text Field Instance Name

wtf? this is my script within the mc,


ActionScript Code:
var externalData:LoadVars = newLoadVars();externalData.onLoad = function(){    news_txt.text = externalData.newsContent;}externalData.load("news_Content.txt");


so what am I doing wrong? thanks.

View Replies !    View Related
Flash Player 5 Discrepency With Instance Names In Mc's & Dynamic Text?
ok, i have a movieClip with the instance name "content" within it I have a dynamic text field with the instance of news_txt which calls for an outside .txt document for its content, but when I try to publish the swf it gives me an error saying:

WARNING: This movie uses features that are not supported in the Flash 5 player
Symbol=content, layer=content, frame=1:Flash MX Text Field Instance Name

wtf? this is my script within the mc,


ActionScript Code:
var externalData:LoadVars = newLoadVars();externalData.onLoad = function(){    news_txt.text = externalData.newsContent;}externalData.load("news_Content.txt");


so what am I doing wrong? thanks.

View Replies !    View Related
Dynamic Variable Names
Hello,

I can't remmeber for the life of me how to create dynamic variable names.

I have an if statement that I want the second part to be dynamic

if (eval(_root.button_1._droptarget) == _root.drop_1)

-----------------------------
So somewhere I set variables
var i = 2
var b = 3

and


if (eval(_root.button_1._droptarget) == _root.drop_1)
becomes:
if (eval(_root.button_1._droptarget) == _root.drop_i)

The 1 at the end is now variable as per the i in the second one.

Any thoughts?

Thanks.....Rob

View Replies !    View Related
Dynamic Variable Names?
for (i=0; i<=numLots; i++) {
currentLot = "_root.vozi.L"+i;
if (("L"+i) == "sold") {
tellTarget (currentLot) {
gotoAndStop(2);
}
}
}


See what I am doing with this line:

if (("L"+i) == "sold") {

I need the loop to go through L1....L72 and check the value of all. All variable values are being passed in from an external file - so I think an array is out of the question. How do I dynamically update the variable name?

View Replies !    View Related
Dynamic Variable Names
how in god's name do I concantenate a variable name from a string and an array index. Here's what I've been trying (this is actionscript, not PHP)...


PHP Code:



var dragNames=new Array(5);
dragNames[0]="Drag1";
dragNames[1]="Drag2";
dragNames[2]="Drag3";
dragNames[3]="Drag4";
dragNames[4]="Drag5";

var targetNames=new Array(5);
targetNames[0]="Target1";
targetNames[1]="Target2";
targetNames[2]="Target3";
targetNames[3]="Target4";
targetNames[4]="Target5";

var i=0;
var thename="";

for(i=0;i<dragNames.length;i++){
    var (eval("dragName" + i)) = dragNames[i];
}

for(i=0;i<targetNames.length;i++){
    var (eval("targetName" + i)) = targetNames[i];
}




I'm trying to end up with a bunch of variables named "dragName1, dragName2,...etc.
I've tried every variation on the above that I can think of and nothing works. This is soooo easy to do in PHP, but not in ECMA script. Please help!

View Replies !    View Related
Dynamic Variable Names
What's the correct syntax for this?

i = 1;
id_1 = 25;
curid = id_[i];

In other words, so that the variable curid will be 25.

View Replies !    View Related
Dynamic Variable Names?
ready to shoot myself in the face..... this should be simple...
why does this not work??
I'm trying to write a function to control several different movie clips on the stage ... there is a movie on the stage called 'prv_vancouver' that should play when moused over, but for some reason the 'province.play();' is seeing 'province' as a string and not an instance name... ! arrghh help!


function mouseout(prov) {
var province = ("prv_" + prov);
province.play();
}



btn_vancouver.addEventListener(MouseEvent.MOUSE_OU T,
function button(){
mouseout('vancouver');
}
);

View Replies !    View Related
Dynamic Variable Names?
If you can create a pseudo-variable name on the fly like this (for instance):


ActionScript Code:
n=1;
_root["myVar_"+n] = "hello";
trace(myVar_n);     // returns "hello"

Can you do it with proper variables? I tried this, but the syntax doesn't check out:


ActionScript Code:
n=1;
var "myVar_"+n:String = new String("hello");

Any ideas?

View Replies !    View Related
Dynamic Variable Names
Erm.... can you use a variable as a variable name? Say...

variable1 = "variableName";

then...

[ variableName ] = "hello";

trace(variableName);

//Output = hello

? I used to know but I've forgotton.

View Replies !    View Related
Can I Have Dynamic Variable Names?
ok so if i need say 10 instances of my class, i use a loop like this


Code:
for (var i:Number = 0; i<antallevels; i++) {
var allLevels:Level = new Level(_root.levelcontainer, "level");
}
This works but i cant call one of them, since they all have the same name(allLevels)
My guess was something like
Code:
var level_[i]:Level = new Level
or
var ["level_" +i]:Level = new Level
but that gives me a syntax error, so no thats not it.

any idea's ? or am i all wrong in using for loop on this

View Replies !    View Related
Dynamic Variable Names
I am creating a series of graphics in a for loop, naming them, and adding eventlisteners for dragging purposes. I'd like to make a way to access my variables with something like this:


Code:
// This worked in AS2, just not in AS3

for(var i=0;i<6;i++){
this["graphicName_" + i].accessSomeMethodHere;
}

//graphicName_0, graphicName_1, etc.
It is simplified here, but that is the basic idea. Any ideas on how this works in AS3?

View Replies !    View Related
Dynamic Variable Names
I am just trying to dynamically name some variables and I am having some troubles.

var i:String = "One";
var ["hey" + i] = "test";
trace(heyOne);

This is the error message I keep on getting.

1084: Syntax error: expecting identifier before leftbracket.

If anyone could help it would be appreciated.

Thanks
Jeff

View Replies !    View Related
Dynamic Variable Names?
I have some code that looks like this:


ActionScript Code:
//adds the movieclip graphic (exported for actionscript) in the flash library with the same name
//randomInt returns an integer between 0 and param-1
            switch (myRandom.randomInt(4)+1) {
                case 1 :
                    addChild(new asteroid1);
                    break;
                case 2 :
                    addChild(new asteroid2);
                    break;
                case 3 :
                    addChild(new asteroid3);
                    break;
                case 4 :
                    addChild(new asteroid4);
                    break;
                default :
                    throw new Error("switch screwy in constructor");
            }
Is there any way to write this code in a loop?
i.e. ("asteroid" + i) = asteroid1, asteroid2, asteroid3, or asteroid4

View Replies !    View Related
Dynamic Variable Names
I have a script that creates a bullet and names it as bullet then the number of shots. Then when I try to change its x position it throws an error.

duplicateMovieClip(_root.bullet0, "bullet"+_root.shots, 0);
_root."bullet"+_root.shots._x = 100;

What corrections do I need to make to get this to work right?

Thanks

View Replies !    View Related
Dynamic Variable Names
I have the following code

ActionScript Code:
si = setInterval(function () {    ind++;    ind>7 ? clearInterval(si) : null;    var tw = new Tween(_root._mc["a"+ind], "_xscale", Regular.easeOut, 0, 200, 60);    new Tween(_root._mc["a"+ind], "_yscale", Regular.easeOut, 0, 200, 60);    tw.onMotionFinished = function() {        new Tween(_root._mc["a"+ind], "_xscale", Regular.easeIn, 0, 100, 40);        new Tween(_root._mc["a"+ind], "_yscale", Regular.easeIn, 0, 100, 40);    };}, 50);
Basically, it goes through 7 loops and animates each object. My problem is that the onMotionFinished function isnt being triggered because it gets overwritten each time before it can. is there a way to dynamically create a variable name to keep track of each Tween? Something like
ActionScript Code:
var eval("tw" + ind) = new Tween(_root._mc["a"+ind], "_xscale", Regular.easeOut, 0, 200, 60);    eval("tw" + ind).onMotionFinished = function() {
except eval appears to only work for objects. Any ideas?

View Replies !    View Related
Dynamic Variable Names?
I want to create a var that concatenates some text with my loop counter, this doesn't work:


Code:
var this["appNm_tf"+i]:TextField = mcMain.createTextField("appNm_tf"+i, getNextHighestDepth() , 0, i * 20, 150, 20);

View Replies !    View Related
Dynamic Variable Names
I'm trying to build a dynamic array.

I can't figure out how to increment my variable name.

I've been sitting here a long time and it feels like my eyes are bleeding.. LOL

springArray[arrayIndex] = [phpIndex+i];

When I use this is outputs NAN, I dunno what that is.

I want to increment phpIndex1 to phpIndex2 then 3 then so on..

Here's the full code.

result_lv = undefined;
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
mystatus.text = result_lv.wrote;

springArray = new Array();
arrayIndex = 0;

phpIndex1 = result_lv.c1;
phpIndex2 = result_lv.c2;
phpIndex3 = result_lv.c3;

i = 1;
do {
springArray[arrayIndex] = [phpIndex+i];
i++
arrayIndex++;
result_lv.myIndex = result_lv.myIndex-1;
} while (result_lv.myIndex-1 ne 0)

// populate the listbox with the data
for(i=0;i<springArray.length;i++) {
spring.addItem(springArray[i][0], springArray[i][1]);
}

} else {
mystatus.text = "Error connecting to server.";
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.id = _global.primary_key;
send_lv.sendAndLoad("http://localhost/Contacts/selectFly.php", result_lv, "POST");

View Replies !    View Related
AS 2.0 Dynamic Typed Variable Names
Hi,
I'm tring to create dynamic var names for a 'Box' class like so:

Code:
for(var i =0; i<3; i++){
set( "box" + i + ":" + "Box", new Box (100+(i*10),100+(i*10),10+(i*10),100+(i*10),_level0,i+10) );
}
This is all fine and dandy, 3 boxes of the proper size, and location are created. The crazy thing is that the variables named box0, box1, and box2 do not exsist! Maybe I shouldn't be using set?, I tried [], and eval to no avail.
the regular line of code that draws a single box from the Box class looks like this:

Code:
var box : Box = new Box (200,100,10,100,_level0,20330);
Any Ideas,
~Dev

View Replies !    View Related
Problems With Dynamic Variable Names.
I want to write code where I have arrays of objects.
I want to write a for loop and have something like:

myObject1 = new Object();
myObject2 = new Object();
myObject3 = new Object();
myObject4 = new Object();
etc...

How can I do this?
I've tried using square brackets... it doesn't work and looks wrong to do anyway.

Any help would be appreciated.

Thanks.


OM

View Replies !    View Related
How To Create Dynamic Variable Names?
Hi guys

I want to create a series of variable names dynamically, but don't know how to do it.

for example, i have a for loop, and want to use the "i" value to be part of a new variable name

Code:

for(i=0;i<total;i++){
var variable+i:String = something;
}



the above obviously doesn't work, can someone enlighten me on what would be the right code?

Many thanks

Joe

View Replies !    View Related
[F8] Loop And Dynamic Variable Names
Hi,

I got this loop going, which creates button on my stages dynamically. Now I need to create color transforms for each of those buttons while I'm still in the Loop. So I know this doesn't work, but while I'm in the loop I would like to do something like this:


Code:
CountryText_mc.MainButton.onRollOver = function() {
var myOverColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOverColor+[i].setRGB(0x2be237);
}

CountryText_mc.MainButton.onRollOut = function() {
var myOutColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOutColor+[i].setRGB(0xFFFFFF);
}


How can I create those color variables, so that this would work. I need to have myOverColor1, myOverColor2, myOverColor3,... and so on. So I can set them anytime I want.

Thanks for help

View Replies !    View Related
Dynamic Variable Names In A Loop
Hi, I'm still a noob at as3 and I'm trying to write a script so that I can affect variable names using a loop.

For example:


Code:
var varName;

function test(event:MouseEvent):void
{
for (var i = 0; i < 5; i++)
{
varName = "a" + i;
var a[i]:Number = i;
trace ( varName + " = " + a[i]);
}
}
essentially I want it to display like this:

a0 = 0
a1 = 1
a2 = 3
a4 = 4
a5 = 5


So I was wandering if there was syntax for what I'm trying to do.

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved