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




Creating Variables With New Names In Loop



What I want to do is to create a new variable appended with a number going thru a loop as so:
Code:
var test = "test";for(var i=0;i<3;i++){//Create a new variable called test0,test1 and test2 with the value of "test" var test = [test + i]; //this is wrong}//Print out all of the variables test0,test1,test2 which should produce 3 test strings in the outputfor(var i=0;i<3;i++){trace(test0);trace(test1);trace(test2);}
Any ideas?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 02-27-2008, 12:22 PM


View Complete Forum Thread with Replies

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

EXTREMELY URGENT - Creating Global Variables Using Names Of Other Variables...
I have variables xtile and y tile within a movie, and I need to create a global variable that will tell all other movies that this particular movie is situated on tile [xtile][ytile], so I need to know how to create the global variable: _root.objectmovie_xpos_xtile_ypos_ytile = true;

I know how to create global variables, and how to have other movies read them, but how do I actually create a VARIABLE with this name? I tried set ("_root.objectmovie_xpos_" + xtile + "_ypos_" + ytile") = true, but that doesn't work (which I kinda knew already but thought I would give it a shot)
any ideas peeps?
please help, its vital to a project I am doing

cheers all

Creating Dynamic Variable Names In Loop
I want to do is to create a new variable appended with a number going thru a loop as so:

Code:
var test = "test";
for(var i=0;i<3;i++)
{
//Create a new variable called test0,test1 and test2 with the value of "test"
var test = [test + i]; //this is wrong
}
//Print out all of the variables test0,test1,test2 which should produce 3 test strings in the output
for(var i=0;i<3;i++)
{
trace(test0);
trace(test1);
trace(test2);
}
Any ideas anyone

Creating Object Names Dynamically Using A Loop
Hi AS3/FLEX professionals,

I am greenhorn in AS3/FLEX comming from AS2/FLASH8.

I have little problem with handling object arragements by creating IDnames dyamically within a FOR-loop. In AS2 it was simple to realize :
FOR (var n=1 ; n<=10 ;n=n+1)
{_root["object_" + n]._visible = true;
}
Has someone of you profressionals any idea how the syntax has to be in AS3 ?
The problem itself is simple, but simple enough for me to solve.

I would be happy, if someone could give me a hint or better a solution.
Thanks for helping in advance.

Best regards from Sven.

Dynamically Creating Variables (variable Names)?
Does anyone know how to do this in Flash? I'd like to dynamically create vars (var names) in a loop, like this:


Code:
var1 = 1;
var2 = 2;
var3 = 3;
...
The problem is that this doesn't pass (because left side of the assigment has to be a property):


Code:
eval("_root."+myKey) = myValue;
This code doesn't work well, also:


Code:
_root[myKey] = myValue;
I succedded in putting name/values pairs into an Array:


Code:
element[myVar] = myValue;
But this is not good for a given purpose, I'd rather have variables in _root.

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?

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

Creating Time Variables With A Loop?
Hello,

I want to create a loop, which would create time variables.

What I mean is I would like to start with 6:00 am go up like:

6:00 am
7:00 am
8:00 am

ect

here is my loop thus far, which is not much

for (start=0; start<=12; start++) {
this["b"+start] = xHour}

I am not sure what to do? Please help. Thanks,

Creating Variables With Loop In LoadVars
I’m calling back some variables from a SQL database. After jumping through the hoops of getting the ASP page written correctly, I’m running into another issue.


Code:
myData = new LoadVars()
myData.load("transferback.asp")
myData.onLoad = function(succes){
if(succes){
_root.objNum = this.objNum;
} else
trace("Error loading data")
}

Once you get the right formatting from the ASP page, then calling the info and setting it to a root level variable is not really a problem. Where I am having an issue is that I’m not sure of the number of variables I will need to call. I will receive the variable number as objNum, but other variables could be from objType1 to objType5 or more.


Code:
myData = new LoadVars()
myData.load("transferback.asp")
myData.onLoad = function(succes){
if(succes){
_root.objNum = this.objNum;
for(i=1;i<=this.objNum;i++){
_root["objType"+i] = this["objType"+i]
_root["objName"+i] = this["objName"+i]
_root["objWording"+i] = this["objWording"+i]
};
} else
trace("Error loading data")
}
When I try and trace my variables that I’m attempting to build from the loop, I don’t get anything back. Am I wrong here in thinking that I should be able to declare variables this way? Since I can determine the number, I figured I would just use the loop.

Any suggestions welcome. Hope that I made this clear enough…

Creating Variables Inside A For Loop
Hi guys ...

The following code sets the x and y coordinates of 6 movieclips:


ActionScript Code:
for (j=6; j>=1; j--) {
        _root["cross_mc"+j]._x = (((Stage.width/2) - 341.6) + ((j-1) * 142.2));
        _root["cross_mc"+j]._y = ((Stage.height/2) - 32.3);
}


But what instead of setting the movieclips x and y coordinates, i just want to create 12 new variables that store the above numbers in?

I can't seem to get this to work, could someone please help me.

Thankyou

Bongo

Dynamically Creating Variables Inside A Loop
I am doing a for() loop. well, can i create variables dynamically inside this loop so that it will look like this:

for (i=0; i=5; i++) {
var (friend+i):String;
}

so that the variables names will be : friend1, friend2, friend3, friend4, friend5 ...

or if that isn't possible, can i refer to a bunch of variables dynamically? because in PHP, it 'echoes' back to flash 'dynamically' created variables but i need to assign and 'refer' to these variables for different instances of this movie clip that has a text field.

the location of this text field is:
_root.friendHolder1.name.text and i want name inside friendHolder1 to have the value of friend1.
and in the same way, _root.friendHolder2.name.text to have the value for friend2 and on and on.

basically (its just an attempt) i'm trying to create smthing that is like myspace. but i have some neat stuff planned for it that myspace doesn't have. so i really need this thing to work. can someone help me out...PLEASE!!! I'm ripping my head here

thanx

Dynamically Creating Variables Inside A Loop
I am doing a for() loop. well, can i create variables dynamically inside this loop so that it will look like this:

for (i=0; i=5; i++) {
var (friend+i):String;
}

so that the variables names will be : friend1, friend2, friend3, friend4, friend5 ...

is this possible? thanks guys?

Duplicating Or Creating MC With A New Names
Help me please! I need to duplicate or create new movie clips with new unique names generated in loop.
In AS2.0 it was done with construction like this:
...
for(i=0; i=100; i++){
createEmptyMovieClip("MC"+i, 1); //or duplicateMovieClip(MC,"NewMC"+1,); for duplicating
}
...
I need analog of this. Help me please!!!

Path Names In For Loop
i have variables r1,r2,r3 and r4. I want to use these vars in my for loop as below.

_root.a1.r1;
_root.a1.r2;
...

To do this I am trying to do

for (i=1, j=53 ; i<5 ; i++, j += 20) {
setProperty ("_root.a1"+("r"+i), _y, j);
}

but it doesnt work... What is the problem?

Concatenating Names In A For-loop
I want to have one line of code, to get four movie clips to load movie clips.
I can't make it work. I don't know how I concatenate the names. Here's the code:
Code:
for(i = 1; i < 5; i++){
"myLoad"+i+"_mc".loadMovie("mc"+i+".swf",1);
}// end for

Array Names / For Loop Please Help
Hi all..

I've got a simple question but I can't seem to answer it. I've created a for loop that I want to create arrays with. I want them named dynamically. So, the code looks like this...


Code:
for (var i:Number = 0; i<5; i++) {

this["array_"+i] = new Array();

}
The code doesn't generate any errors, but when I trace any of the generated array names, I get an undefined response. I'm sure it's a simple fix. Any help is very, very much appreciated. Thanks...

Instance Names From For Loop
Hello,

I am using a for loop to create multiple image loaders and have a question. I can get the script to work fine, but I am wondering if there is a way to make a specific instance name for each loader created, instead of just attaching a .name attribute.

here is my code, in case this helps answer the question:

Code:
for(var i:int=1; i<=5; i++){
var refNum:Number = i;
var kitsTNStartX:Number = -9;
var kitsThumbLoader:Loader = new Loader();
var kitsThumbRequest:URLRequest = new URLRequest("images/kits/tn/"+i+".jpg");
var kitsImageRequest:URLRequest = new URLRequest("images/kits/webRes/" + i + ".jpg");
kitsURLArray.push(kitsImageRequest);
kitsThumbLoader.x = kitsTNStartX+i*50;
kitsThumbLoader.y = 581.8;
kitsThumbLoader.load(kitsThumbRequest);
addChild(kitsThumbLoader);

kitsThumbLoader.filters = filterArray;

var kitsThumbB:MovieClip = new MovieClip();
kitsThumbB.graphics.beginFill(0x000000);
kitsThumbB.graphics.drawRect(kitsThumbLoader.x, kitsThumbLoader.y, 45,45);
kitsThumbB.graphics.endFill();
kitsThumbB.alpha = 0;
kitsThumbB.buttonMode = true;
addChild(kitsThumbB);

kitsThumbB.name = "kitsB" + i;
kitsThumbB.addEventListener(MouseEvent.CLICK, loadImage);
kitsButtonArray.push(kitsThumbB.name);
}
As it is right now, I am referencing each loader by the .name attribute attached in the for loop, but am feeling limited by it. If there is a way to create an instance name other than [object loader], I would love to hear about it!

Thanks in advance y'all!
varPBR

For-loop With Variable-names
Hello!
I have 16 movieclips that have been created dynamically. I want each of them to change alpha when I press them.
It functions if I do it one by one but I want a loop and my code doesn´t work.

The movieclips name are S0, S1, S2 ....


Code:
for (q=0; q<16; q++) {
["S"+q].onPress = function() {
["S"+q]._alpha=40;
}
}

Using For Loop With Instance Names
Hi everyone,

I'm trying to run through a for loop and use the "i" variable to change which instance name I'm referring to, which I then store in the variable x. I then use the instance name to call a function.

Why doesn't this work -


Code:
for (var i:Number = 1; i<6; i++) {

var x = "main_mc.ball" + i + "_mc";
trace(x);

x.onRollOver = function() {
trace("hgjghj");
ballRollOver(this);
}
x.onRollOut = x.onDragOut = function() {
ballRollOut(this);
}
x.onRelease = function() {
ballClick(this);
}

}
The trace(x); produces the expected results -
main_mc.ball1_mc
main_mc.ball2_mc
main_mc.ball3_mc
main_mc.ball4_mc
main_mc.ball5_mc

... which suggests that this code should work. However the rollovers don't work (I don't even get the trace that's sitting within the rollover function).

HELP!!!!

For Loop Overwriting Names
I am creating a photobrowser with different categories. In creating the backend, I thought it would be nice to be able to drag the different category buttons (mcs) to change the order. I'm running into an issue because I'd like to rename each instance to reflect the new order. I thought a for loop would do it, but if I need to rename for instance "category5_mc" to "category6_mc" before I have renamed "category6_mc" then I can't rename "category6_mc" because "category5_mc" has already been renamed this. Has anyone run into this before, and if so, how did you get around it.

I am thinking that I determine the direction the for loop should go depending on whether the category has been dragged to a higher or lower number.

Any advice will be appreciated.

How To Set The Mc Instance Names In A For Loop?
hello,

i'm a bit confused. on my stage i have some buttons with the instance name ma01 to ma027.
this is my code but the buttons won't work in this way. the trace shows me the right instance name. can someone give me a hint?

Code:

for(i=0;i<27;i++){   
   var t = "ma0"+i;
   trace(t);   
t.onRollOver = function(){
trace("over");
   }
   
t.onRollOut = function(){
trace("out");
   }   
}


thanks a lot.

-Tukinu

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

Dynamically Creating Variable NAMES
Lo peeps

Ok so here's the dilly y'all (been listening to waaay too much rap)

I'm making a photo gallery type thing and I want to dynamically create the thumbnails using actionscript. The snag being that I'm making them enlarge based on proximity so I need to move the registration point from top left to the center. So I found a handy little class which helps me with this but here is the problem. It takes a lot of setup to move each image's registration point to the center and it could be that there are 30 thumbnails per page.

So being the clever guy I thought I was I tried to just execute all the elements using a for loop and thus it would just execute it x amount of times saving me loads of time in repetion.

ok so here's a snippet of the code: (this code would have to be typed for each different variable)

import com.darronschall.*;
var photo2:MovieClip;
DynamicRegistration.initialize(photo2);
var newH = photo2._height / 2;
var newW = photo2._width / 2;
photo2.setRegistration(newH, newW);

So to execute this code like say 30 times for 30 MC's named photo1-30, I thought something like this may work:

var i:Number;
for (i = 0; i < 30; i++) {
var photo+i:MovieClip;
DynamicRegistration.initialize(photo+i);
var newH = photo+i._height / 2;
var newW = photo+i._width / 2;
photo+i.setRegistration(newH, newW);
}

but it doesn't even get past creating the variable name dynamically.

So is there a way to do this? or an alternative?

Thanks

Syllogism

Creating Sprites With Dynamic Names...
Code:
var name = "newSprite1";
var name:Sprite = new Sprite;
The above code obviously doesn't create a sprite called "newSprite1".
Nor does...


Code:
function newSprite(nameofsprite:String):void
{
var nameofsprite:Sprite = new Sprite;
};
newSprite(newSprite1);
but how would you create a sprite, passing in a piece of data as it's name?

My particular problem is to create and position a Sprite for each of a set of items in an XML file (into which i can later add jpeg children as they load). I've sorted out the XML load fine and I want to be able to put something like...


Code:
var "image"+property.thumbnail.@id+"Sprite":Sprite = new Sprite;
inside my for loop to create a Sprite of name "image[id]Sprite" for each XML item, but i can't figure out how to do this? (Tracing "property.thumbnail.@id" returns 1,2,3 on each repeat of the for loop).

Could I perhaps do it by creating many sprites of the same name and assigning the .name property to each instance? If i then had 3 Sprites called "image" say, with .name properties of "1","2" and "3", how might I go about loading bitmap data into a particular one?

Thanks in advance for any help!

Creating Instances With Dynamic Names
Hi All,

I have an onEnterFrame function where every time it runs I want to create a new graphic named like this -

boundaryGraphics0, boundaryGraphics1... boundaryGraphics + boundaryCount

Where boundaryCount inrements by 1 each time.

This is something I could have done easily with AS2, doing something like this -


ActionScript Code:
this.createEmptyMovieClip("boundaryGraphics", "boundaryGraphics" + boundaryCount, this.getNextHighestDepth());
this["boundaryGraphics" + boundaryCount]._alpha = 50;

But I'm having real trouble in AS3. Am I missing the point? Could someone point me in the right direction?

My current code is this (there's nothing dynamic about it yet) -


ActionScript Code:
var boundaryCount:Number = 0;

var boundary:Sprite = new Sprite();
addChild(boundary);

stage.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
function onLoop(evt:Event):void
{
    drawBoundary();
    boundaryCount++;
}

function drawBoundary():void
{   
    var boundaryGraphics:Graphics = boundary.graphics;
   
    boundaryGraphics.lineStyle();
    boundaryGraphics.beginFill(0x993300, 1);
    boundaryGraphics.drawRect(bX, bY, bW, bH);
    boundaryGraphics.endFill();
}

This all works and everything but I want each shape created to have its own instance name so that a few frames down the line I can start deleting old graphics that have been drawn (when they are no longer needed)

Thanks very much!

Matt

Creating Dynamic Variable Names
okay let's say I want to make a variable named number1

var number1:Number = 0;

how would I do something to dynamically change the variable name like in a loop

for(var i:uint =0;i<5;i++){
var number[i]:Number = i;
}

Creating New Objects With Increasing Names
Hello guys, straight to the point... I have a list of "Users" that I am showing in the fListBox component. Each user needs to be an object with 3 datas, (obj.name, obj.pos, and obj.lvl) Now I have a button and input text that is supposed to add a "user" to the list and create a new object. So I want to be able to type "James" then hit butt_addUser and have it create an obj:

user1=new Object();
user1.name="James"
user1.pos=0/null
user1.lvl=0/null

then I will simply do...

userList_list.addItem(user1.name,user1.pos)

...to update the list component.
Can someone please tell me how I can create a NEW obj with a name that increases upon each creation? Thanks to anyone who reads this with the intention to help. Those of which are extremely appreciate by newbish folks such as myself.

Variable Names Incremented With For Loop?
Hey all,
This is whaat I'm trying to do...

for (var i = 0 ; i < UpperTextFields; i++)
{
_root.createTextField(utf[i], utf[i]_z, utf[i]_x, utf[i]_y, utf[i]_wide, utf[i]_tall);
utFormat[i] = new TextFormat();
utFormat[i].font = utFormat[i]_font;
}

I'm loading the variables UpperTextFields, utf1, utf1_z, utf1_x, uft1_y, utf1_wide, utf1_tall and utFormat1_font from a textfile. ignore the variable I'm trying to copy their values to for now. I'm sure this is a simple syntax issue on how I'm adding the "1" to my variable names... Can someone help???


Thanks.

[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

For Loop And Incrementing Object Names
I'm trying to loop through some objects, and I'm doing something wrong.

I'd like to do the following to some sound channel objects.

for (var n:Number = 0; n<5; n++) {
_root["sc" + n].stop();
}

Obviously, I can't do that in AS3, but that's what I want to do. The _root path is not important. I only added it because that syntax used to work in AS2. How can I loop through incrementing object names?

Thanks.

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.

Give Instance Names To Mcs In For Loop
Hello, i have a for loop setting up items to be menu buttons, and at the moment part of my code looks like this:


PHP Code:




private var mainmenu:Array = new Array();
private var mainaddress:Array = new Array();
private var MainMenu:MovieClip = new MovieClip;

mainmenu = ["about","design","artists","projects","contact"];
            mainaddress = ["about","design","artists","projects","contact"];
            
            
            for (var i:Number = 0; i<mainmenu.length; i++) {
                trace(mainmenu[i]);
                Box = new box();
                Box.x = 0;
                Box.y = spacing + i* (Box.height + spacing);
                Box.name = mainaddress[i];
                Box.hello.butText.text = mainmenu[i];
                MainMenu.addChild(Box);
                Box.addEventListener(MouseEvent.MOUSE_OVER, over);
                Box.addEventListener(MouseEvent.MOUSE_OUT, out);
                Box.addEventListener(MouseEvent.CLICK, menuclick);

            }
            
            trace(" ");
            
            addChild(MainMenu);
            MainMenu.x = MainMenu.width + 20;
private function menuclick(evt:MouseEvent):void {
            switch (evt.target.parent.name){
                case "about" :
                trace("this is working")
                break;
                case "design" :
                trace("this is working")
                break;
                case "artists" :
                trace("this is working")
                break;
                case "projects" :
                trace("this is working")
                break;
                case "contact" :
                contact.x += 20;
                break;
                default :
                trace("this is working");
                break;
            }
        }








So, when you click any of the buttons that are generated, they each say "i'm working" etc, but with my last line, clicking contact doesn't move the contact menu as it says "contact" is an unidentified property. How do i refer to the buttons i have created if i want to animate them? the idea is that, when you click a button the buttons beneath it will scroll down, then some sub menu movieclips i have made will scroll in from the side.

Thank you so much for any help in advance, you guys are all awesome.

How To Use AddChild With A Loop And Dynamic Names?
Hey people,

I am trying to use addChild() for hundreds of movie clips by using a loop, but I don't know how to do this in AS3.0.

Right now I have this:

for(var i:Number = 0; i<=100; i++){
var squareClip0:squareClip= new squareClip();
this.addChild(squareClip0);
};

I am trying to do the equivalent of this from AS2.0:

for(var i:Number = 0; i<=100; i++){
duplicateMovieClip("squareClip_mc", "squareClip"+i+"_mc", i);
};

I have the linkage set up already to load it from the library.

I need to create movie clips with an increment in the file name, because I don't want to name all these clips individually.

Any help is greatly appreciated.

Concatenating TextBox Names In A For Loop
Basically what I'm doing is trying to populate a group of text boxes with text from an array using a for loop (this is for a game I'm making). I have a movie clip called mainMenu_mc that's the main menu. Inside of mainMenu_mc I have different frames for the different sub-menus (Item, Stats, Equipment...). In the Item Menu frame I have a group of text boxes named itemText0, itemText1, itemText2, etc. I also have an array called inventoryArray. Inside of inventoryArray I have two variables - itm stores the item names and qty stores the quantities of each item.

Here's the code I'm using:

Code:
for (i=0; i<inventoryArray.length; i++) {
this["mainMenu_mc.itemText"+i].text = inventoryArray[i].itm;
}
This just leaves me with a bunch of blank text boxes. I tried mainMenu_mc.this["itemText"+i].text and it gave me a formatting error. I also tried mainMenu_mc.eval("itemText"+i).text and that didn't work either. So how would I code this?

Changing Variable Names In A Loop
I have a text file containing strings &strtxt0001… &strtxt0002… &strtxt0003… loaded into a load variable called lv.

It want to put them in a array.

This code works:

data_array[counter_int] = lv.strtxt0001;

...but I want to loop though all of the fields, of which there will be hundreds. I thought something like this might work:

data_array[counter_int] = lv.strtxt[counter_int];

…but it doesn’t. Does anyone know if you can use a variable in a variable name like that? Or has anyone any other suggestions?

Thanks.

Setting Variable Names In Loop
You know how you can use those array braces like in the advanced paths tutorial right ?

ActionScript Code:
for (i=0;i<someValue;i++){
_root["SomeName"+i]._x = 200;
//etc
}
I've been looking for something similar to do with variables, but can't get it to work like this.

For instance, I have a function like this:

ActionScript Code:
someFunction = function (X_1,Y_1,X_2,Y_2,X_3,Y_3){
for (i=1;i<=3;i++){
_root["someMc"+i]._x = this["X_"+i];
//the this["X_"+i] part is where it fails
}
}

AS2 : Using Variables As Array Names/ Dynamic Array Names
Hi,

Hoping someone here can help me with this problem:-

This code works (as part of a loop):-

attachMovie(x1r1[i], "Aln1" + i, i);

where x1r1 is the name of an array which gets cycled through.

However, this array name will change on a new level, (lvl) so what I really
need is something that works like this:-

lvl = 1;
var ex = "x"+lvl"+r1"
attachMovie(ex[i], "Aln1" + i, i);

However flash does not see ex as equal to "x1r1" for the purposes of
using it as an array name. Not even if I use "eval".

Any suggestions?

Thanks

Michael.

Dynamically Creating Movie Clip Names - Help
for (i = 1; i < 5; i++){
_root.createEmptyMovieClip("Thumb_" + i, i);
Thumb._x = 10 + x;
Thumb._y = 10 + y;
Thumb_[i].loadMovie("thumb_" + [i] + ".jpg");
x+=10;
y+=10;
}

^ obviously flawed


I need for the code to load "i" number of images onto the movie.
I'm trying to make this as simple as possible. So instead of hard coding it, I made it into a loop.
but it won't work, partly because I messed up the syntax. partly because I don't know what I'm doing

Creating Functions And Passing Instance Names To It.
I have a bit of script that I'd like to turn into a function. I need to call this function from a button located within a movieclip (this clip is the one the function will act upon) I need to pass the instance name of this clip into the function. Here is what I have, placed on the main timeline, but it's not working:


Code:


function moveWindow(window) {
_root.window.gotoAndPlay("Open");
_root.createEmptyMovieClip("windowAnchor_mc",0);
_root.windowAnchor_mc._y = _root.window._y;
var winanch:String = _root.windowAnchor_mc._y ;
trace (winanch);
_root.window.onEnterFrame = function() {
_root.window._y -= (_root.window._y-_root.News_Window_mc._y)*.5;
_root.News_Window_mc._alpha = _root.News_Window_mc._alpha-10;
_root.Photos_Window_mc._alpha = _root.Photos_Window_mc._alpha-10;
_root.Store_Window_mc._alpha = _root.News_Window_mc._alpha-10;
_root.Shows_Window_mc._alpha = _root.News_Window_mc._alpha-10;
_root.Lyrics_Window_mc._alpha = _root.News_Window_mc._alpha-10;
trace("hello");
trace (winanch);
if (_root.window._y == _root.News_Window_mc._y) {
delete _root.window.onEnterFrame;
}
};
}


And then on my button

on (press) {
moveWindow(this);
}

or moveWindow(_root.Contact_Window_mc);

Also, as you can see I have a couple of repetitous commands (changing the ._alpha of 5 movie clips). If I were in php, I'd stick the names of those in an array and do a "for each" loop on it to cut down on all of that code - is there a way to do that in flash?

Problem With For-loop And Mc-instance-names Inside
Flash 6.
Within an enterFrame code I got following code:

Code:
_root.shadows(_root.MCShadowholder.MCShadow1,_root.MCObject1._x,_root.MCObject1._y);
_root.shadows(_root.MCShadowholder.MCShadow2,_root.MCObject2._x,_root.MCObject2._y);
_root.shadows(_root.MCShadowholder.MCShadow3,_root.MCObject3._x,_root.MCObject3._y);
_root.shadows(_root.MCShadowholder.MCShadow4,_root.MCObject4._x,_root.MCObject4._y);
_root.shadows(_root.MCShadowholder.MCShadow5,_root.MCObject5._x,_root.MCObject5._y);
_root.shadows(_root.MCShadowholder.MCShadow6,_root.MCObject6._x,_root.MCObject6._y);
_root.shadows(_root.MCShadowholder.MCShadow7,_root.MCObject7._x,_root.MCObject7._y);


_root.shadows is a function that returns x and y coordinates of MCShadow1-7 based on the coordinates of MCObject1-7.
_root.MCShadowholder holds movieclips previously created.
MCShadow1-7 and MC Object 1-7 are movieclips previously created.

This works very well, but now I wish to transform that code into a for-loop since I want to enhance the code. Therefore I wrote following code:


Code:
for (i=1; i<_root.NumberOfShads+1; i++) {
NameShadow = new Object("MCShadow"+i);
NameObject = new Object("MCObject"+i);
ShadowInstance = _root.MCShadowholder.NameShadow;
ObjectInstance = _root.NameObject;
_root.shadows(ShadowInstance, ObjectInstance._x, ObjectInstance._y);

//debugging:
trace("Object?: "+typeof (NameShadow));
trace("MCShadow X?: "+NameShadow);
trace("Object?: "+typeof (NameObject));
trace("MCObject X?: "+NameObject);
trace("Movieclip?: "+typeof (ShadowInstance));
trace("_...MCShadow X?: "+ShadowInstance);
trace("-----------------");
}


NumberOfShads is a constant defined in _root.Frame1 and is set to 7 atm.
NameShadow, NameObject, ShadowInstance and ObjectInstance are not created before this code.

The trace-commands return:

Object?: object
MCShadow X?: MCShadow1
Object?: object
MCObject X?: MCObject1
Movieclip?: undefined
_...MCShadow X?:
-----------------
.
.
.
-----------------
Object?: object
MCShadow X?: MCShadow7
Object?: object
MCObject X?: MCObject7
Movieclip?: undefined
_...MCShadow X?:
-----------------

so the only lines not working are:

Code:
ShadowInstance = _root.MCShadowholder.NameShadow;
ObjectInstance = _root.NameObject;


Most Probably because Name Shadow and NameObject shouldnt be "objects". The mustnt be strings either - that I know.

Can anyone tell me how I can make those lines work?

For Loop + AddChild. How To Get Unique Instance Names?
I'm totally stumped. Can someone give an example of a for loop that creates mc's which have unique instance names and can be controlled by some as later in the file?

Trouble Creating Unique Instance Names For AttachMovie
Hello everybody! I'm currently making a TicTacToe game to help build my Flash experience and I've come across an issue. I'll try and explain what everything is doing in my code thus far. I know it's a lot of code for a forum post, but I don't want to leave anything out as someone may have a really nice way to work with this.


Code:
//this will be switched to a user defined value (1 or 2), depending on which person the
//user decides should go first. currently it is set up for the 2nd player to go first
new _global.whosTurn();
_global.whosTurn = 2;

//this sets all cells DISABLED so, at the beginning of the game, any cell is selectable
cell1_isUsed = false;
cell2_isUsed = false;
cell3_isUsed = false;
cell4_isUsed = false;
cell5_isUsed = false;
cell6_isUsed = false;
cell7_isUsed = false;
cell8_isUsed = false;
cell9_isUsed = false;
theDepth = 100;

//cell_status : 1==X 2==O nil==0(zero). This keeps track of which cell belongs to X and to
//O, so that the checkForWinner function can keep track of when someone has won
var cell1_status = 0;
var cell2_status = 0;
var cell3_status = 0;
var cell4_status = 0;
var cell5_status = 0;
var cell6_status = 0;
var cell7_status = 0;
var cell8_status = 0;
var cell9_status = 0;

//this function is incomplete, it will check to see if any user has a tic-tac-toe and declare the winner
function checkForWinner() {
if ((cell1_status && cell2_status && cell3_status) == 1) {
whosTurn_txt.text = "Player 1 wins.";
}
}

//this function is responsible for alternating turns between players, not much else to say here
function switchTurns() {
if (_global.whosTurn == 1) {
_global.whosTurn = 2;
} else if (_global.whosTurn == 2) {
_global.whosTurn = 1;
}
}

//this minor function simply gets an x and y value for the placement of the X or the O, if
//you look further down at the markItUp function these values play the part of positioning
//the X or the O in the center of whichever cell the user selected
function placement(which_cell) {
placementX = which_cell._x;
placementY = which_cell._y;
}

//this is the function that is screwed up. the first X and the first O that are put onto the
// stage are great and do what it is supposed to do, but after that what I'm doing (due to
// my lack of coding knowledge ) is putting multiple movie clips on the stage with the SAME
// instance name. this is where the problem lies and where I need help figuring out how to
// give each movie clip its own unique name
function markItUp(which_cellStatus) {
if (whosTurn == 1) {
attachMovie("marker_X","xMarker",theDepth);//need to somehow declare unique movieclip instance names
_root.xMarker._x = placementX+8;
_root.xMarker._y = placementY+12;
which_cellStatus = 1;
switchTurns();
} else {
attachMovie("marker_O","yMarker",theDepth);//need to somehow declare unique movieclip instance names
_root.yMarker._x = placementX+8;
_root.yMarker._y = placementY+12;
switchTurns();
}
}

//this function handles all the above functions when a user clicks on a cell
function clickedCell(which_cellIsUsed, whichCell, cell_status) {
whichCell.onRelease = function() {
if (which_cellIsUsed == false) {
placement(whichCell);
markItUp(cell_status);
which_cellIsUsed = true;
theDepth++;
} else {
whosTurn_txt.text = "Pick a different cell";
}
//checkForWinner();
};
}

//sets up the clickedCell function
cell1.onPress = clickedCell(cell1_isUsed, cell1, cell1_status);
cell2.onPress = clickedCell(cell2_isUsed, cell2, cell2_status);
cell3.onPress = clickedCell(cell3_isUsed, cell3, cell3_status);
cell4.onPress = clickedCell(cell4_isUsed, cell4, cell4_status);
cell5.onPress = clickedCell(cell5_isUsed, cell5, cell5_status);
cell6.onPress = clickedCell(cell6_isUsed, cell6, cell6_status);
cell7.onPress = clickedCell(cell7_isUsed, cell7, cell7_status);
cell8.onPress = clickedCell(cell8_isUsed, cell8, cell8_status);
cell9.onPress = clickedCell(cell9_isUsed, cell9, cell9_status);
Sorry, I know it's a lot of code for someone to look at without being paid, but I would appreciate any help anyone could provide.

~Jason

Instance Names With Loop Values Attached To The Name Possibl
Hi everyone, I was just wondering if it was possible to have loop values attached to variable or instance names.

I know that it is possible in certain situations such as the createEmptyMovieClip() or the attachMovie() where you can declare the new instance name+the value of the loop but I was hoping to be able to expand beyond that to use with properties such as ._x

I'm looking for a way to set the properties with loops instead of having to physically type them out

i.e.
mc_1._x
mc_2._x

I hope this question makes sense and doesn't confuse anyone

Variables As Mc Names
so i have this problem. i am trying to use a variable to tell my movie which movie clip to play--each nav button sets the variable determining which movie clip plays. after clicking a button, several animation type things happen to rearrange the page before the content for the specific section appears.

i have this code on a button in the first frame:

on (release) {
gotoAndPlay(2);
section = "about";
}

then around frame 30 this is in the frame:

section.gotoAndStop(2);
stop();
trace (section);

but then the section never appears. i did a trace and the right variable (about) is showing up. i tried putting the contents of the movie clips in their own frames, and that works, but it would be easier if they were in movie clips instead.

any thoughts on why that isn't working?

[tween Class] Creating Multiple Tweens And Assign Variable Names
Hi there:

I'm trying to create various tween for various movies, comething like this:


Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;

function fade_anim(mc, max, min, tempo) {
var bot_alpha:Tween = new Tween(eval(mc), "_alpha", Regular.easeIn, max, min, tempo, true);
bot_alpha.onMotionFinished = function() {
fade_anim(mc, min, max, tempo);
};
}

fade_anim("barra3",90,20,1);
fade_anim("barra4",30,80,1);
this code works without problem.

My problem is how to call a specific tween to stop it, for example: onrollover stop the tween assigned to "barra3" mc for example

I can't use bot_alpha.stop() it doesn't work. I think it's because i have multiple "bot_alpha" tweens, i need something to dynamic create bot_alpha1; bot_alpha2; ... ...

Thanks for the help!

Instance Names As Variables
I am trying to have one movie clip give a play command to another movie clip based on a variable set by the previously played movie clip. I can make it work when I put the instance name directly into the script. However, when I switch out the instance name for a variable name it does not work. Is it possible to use a variable in the place where an instance name would normally go? I have tried using Tell Target and dot syntax.

Changing Variables Names
is it possible to change a variable name automaticlly (at desin time)?
i have a var a
i want to change it let's say to iMax, in all the actionscript of the movie.
something like find and replace.

Variables Varible Names
Ok i got a problem, i ll explain briefly my job:

i'm doing a page that can be only reached with a login and pass word... the problem is that my client don't know a single thing in flash and want to be abble to create login and pass word for new user without having to contact me each time.

so i planned to have the L/P stored in an external text file so he just have to had some..... the variable for the l/p are stated like this : log1, pass1, log2, pass2, log3 pass3 etc..... i wanted my clip to scan the login name entered in the field and compare it with the login in the text file. So to achive that i would have to but a variable in my variable name somthing like if log(x) = input go to........ else set x =x+1..... this way all the log are compared one after the other. once the log match one of the log in the txt (say input = log12) flash scan to see if pass12 = inputpass......

well it's the idea... the problem is that i can't manage to insert the variable x (the number of the log ) in my varible name so flash scan all the log(x) varibles one after the other without having to prog them all one by one

anyone knowa way to achive that ?????

Variables For Scene Names
I am now creating a single movie with multiple scenes and have a question on "gotoAndPlay".

In another post someone showed me how to use a variable in "loadMovie" instead of hardcoding which movie to load. The second to the last frame had a "Stop" action and the last frame's action read:

loadMovie(swftoload,0);

The button's action read:

on (release) {
swftoload = "land.swf"
play();
}

This action restarted the loaded movie and loaded land.swf.

I was trying to accomplish the same thing with "gotoAndPlay". The last frame's action is:

gotoAndPlay(scenename,framenumber);

My button's actions is:

on (release) {
scenename = "scene 3"
framenumber = "3"
play();
}

However, I get errors stating that the scenename needs to be quoted. Quoting "scenename" also create errors since there is no scene named "screnename".

Is what I'm trying to accomplish possible? And if so, how?

Thanks,

Robert

Variables And Instance Names
My movie sends data to the database if, and only if, the text is stored in an input text field labeled using the instance name (not the variable name). The fields are on separate frames and then shown altogether as a summary that can be printed. The only way I know how to do that is to label the input text boxes with the variable name. But if I have it labeled w/both the variable name and instance name, it won't send. If I get the user to enter data in the variable named boxes, how can I populate the summary where the text fields are labeled with the instance name?

Thanks

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