-
help with dynamic assignment construction...
ok... here goes~
i have made copies of an MC on the field like this:
for(x=0;x<=10;x+=1){
UnitNum = "Unit'+x;
duplicateMovieClip(_root.unit, UnitNum,x);
}
my problem is now i need to access each of them individually to assign a value individual to them so they "remember" their numbers,
like:
_root.unit1.no = 1
_root.unit2.no = 2
_root.unit10.no = 10
but how do i insert an assignment in the loop to make that assignment?
_root.unit+x.no = x;
doesn't work...
nor does
eval("_root.unit"+x+".no") = x;
but you sort of get the drift... how do i call such an assignment?
-
Banned
Hi,
Why not just use the number variable assigned to each MC....
UnitNum = 'Unit'+x;
That way..
UnitNum = unit1, unit2, unit3.. etc
Just access the number of the duplicated MC.
You can also assign a variable name to the duplicate movieclip method and access the variable name, saves typing......
for(x=0;x<=10;x+=1){
myUnit = duplicateMovieClip(_root.unit, UnitNum,x);
UnitNum = myUnit + x;
myUnit._x = UnitNum + 10;
myUnit._visiblity = whatever;
}
NTD
-
Originally posted by NTD
Hi,
Why not just use the number variable assigned to each MC....
UnitNum = 'Unit'+x;
That way..
UnitNum = unit1, unit2, unit3.. etc
Just access the number of the duplicated MC.
You can also assign a variable name to the duplicate movieclip method and access the variable name, saves typing......
for(x=0;x<=10;x+=1){
myUnit = duplicateMovieClip(_root.unit, UnitNum,x);
UnitNum = myUnit + x;
myUnit._x = UnitNum + 10;
myUnit._visiblity = whatever;
}
NTD
whoa whoa... i'm not quite following this logic...
when u say
myUnit = duplicateMovieClip(_root.unit, UnitNum,x);
what the heck does that do??
i had the following code,
unitNum = "unit"+x;
myUnit = duplicateMovieClip(_root.unit, unitNum, x);
myUnit.num=x;
in my loop sort of thing, and when i traced for the "num" variable from within the unit itself (trace(this.num) all i get is a stream of undefineds...
am i not understanding something right?
-
Banned
Hi,
I have looked over this post a couple of times now, and to be honest, I am not sure what I was thinking. I cant make sense of that code myself. I think I was trying to say in a poorly constructed way that you can access each of the duplicated MC's witha a variable name, but after looking at your code again, you have done that already(unitNum = "unit"+x;). In your code, if you trace UnitNum...... dont you get the output UnitNum1,UnitNum2, .... etc? You can access each of the duplicated movies with that..... _root.UnitNum5._x = whatever;.. or _root.UnitNum5.number = 5; I apologize for the inaccurate post, I have been up for too long apparently. Hope I didn't sidetrack you more.
Sorry
NTD
-
Originally posted by NTD
Hi,
I have looked over this post a couple of times now, and to be honest, I am not sure what I was thinking. I cant make sense of that code myself. I think I was trying to say in a poorly constructed way that you can access each of the duplicated MC's witha a variable name, but after looking at your code again, you have done that already(unitNum = "unit"+x. In your code, if you trace UnitNum...... dont you get the output UnitNum1,UnitNum2, .... etc? You can access each of the duplicated movies with that..... _root.UnitNum5._x = whatever;.. or _root.UnitNum5.number = 5; I apologize for the inaccurate post, I have been up for too long apparently. Hope I didn't sidetrack you more.
Sorry
NTD
yup that was my point, but now i need to access each individual MC dynamically as i create them... so that each run of the loop allows me to set a few variables within the newly made MC... am i making sense?
let's say the loop runs 100 times, that means i'll have 100 MCs with individual names, and i need all of them to have a "no" variable containing unique numbers referring to their order. but how do i construct an assignment based on the x amount in the loop to call each MC individually?
ie how would construct this in flash terms??
_root.unit<<x>>.no = x;
where <<x>> = loop variable
therefore if:
for (x=0;x<5;x+=1)
then u'd get like
_root.unit1.no = 1;
_root.unit2.no = 2;
_root.unit3.no = 3;
_root.unit4.no = 4;
_root.unit5.no = 5;
-
this works:
code:
for (x=0; x<=10; x += 1) {
UnitNum = "Unit"+x;
duplicateMovieClip(_root.unit, UnitNum, x);
_root[UnitNum].no=x;
}
while this is legal, you will probably find it more powerful to assign the clips and their values into a holder array code:
clipArray=new Array();
for (x=0; x<=10; x += 1) {
UnitNum = "Unit"+x;
duplicateMovieClip(_root.unit, UnitNum, x);
clipArray[x]=_root[UnitNum];
clipArray[x].no=x;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|