all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

Addressing a variable - help please


Addressing a variable - help please bderber
10/14/2005 8:46:57 PM
flash actionscript:
I have a swf that loads a swf. The child spins out a moveclip for screen
elements. I am attempting to address, based upon user selection, an array
element located at:

_root.mc_StickerHolder.sticker1Line[1][6]

No matter how I iterate eval() or this[] I cant get it. I finally constructed
the path as a string and figured I would attempt to address the variable with
eval() or this[].

Using this code.....

BOB = "_root.mc_StickerHolder.sticker" + SelectedStickerType + "Line[" + i +
"][6]";
trace(BOB); = returns the correct path
trace(eval(BOB)); = returns undefined
trace(this[BOB]); = returns undefined

Any suggestions appreciated.
Re: Addressing a variable - help please NSurveyor
10/14/2005 10:43:55 PM
_root.mc_StickerHolder.sticker1Line[1][6]

should work... UNLESS the path to the array is wrong...

Try the following:

trace("_root: "+_root);
trace("_root.mc_StickerHolder: "+_root.mc_StickerHolder);
trace("_root.mc_StickerHolder.sticker1Line:
"+_root.mc_StickerHolder.sticker1Line);
trace("_root.mc_StickerHolder.sticker1Line[1]:
"+_root.mc_StickerHolder.sticker1Line[1]);
trace("_root.mc_StickerHolder.sticker1Line[1][6]:
"+_root.mc_StickerHolder.sticker1Line[1][6]);

By doing this, you will find out which part of the path is incorrect.
Re: Addressing a variable - help please bderber
10/14/2005 11:00:05 PM
I was not clear enough.....

Hard coded the piece works fine. It is constructing the path with eval() or
this[] that seems to be screwing it up.

The 1 in the middle and the first position of the array are both dynamc. I
hvae not found a way to use eval() or this[] to make it work. for example

eval(_root.mc_StickerHolder.sticker" + variable_x + "Line[" + variable_y +
"][6]" returns "undefined"......

any thoughts?

Re: Addressing a variable - help please NSurveyor
10/14/2005 11:08:39 PM
Ahhh sorry, I misunderstood your question. You should be using:

BOB = _root.mc_StickerHolder["sticker"+SelectedStickerType+"Line"][ i ][6];
Re: Addressing a variable - help please bderber
10/14/2005 11:23:23 PM
PRIMO.... here's what finally did the trick but it was just a path issue for
one variable that I saw immediatley once I saw your answer........

BOB =
_root.mc_stickerHolder["sticker"+this._parent.selectedStickerType+"Line"][ i
][6];
trace(BOB);

A coupld of questions. Why no dot syntax between the name of the variable and
the movie clip mc_stickerHolder? There is dot syntax in the
this.parent.selectedStickerType so I don't understand when it is necessary and
when not.

Second item. The idea of "this._parent" seems redundant, but If I do not use
it is returns "undefined." The variable resides in the movie clip above this
one which is loaded mid-stream but I would have assumed _parent. would do.

bob
Re: Addressing a variable - help please NSurveyor
10/15/2005 12:11:12 PM
Think about it... what is [ ] syntax doing? You have path[prop]

It will look in "path", for an item with name "prop". In your code, what are
you actually evaluating? The only thing that is needed to be evaluated is:
"sticker"+this._parent.selectedStickerType+"Line. _root.mc_stickerHolder is
already a good reference. So, if you used:

_root.mc_stickerHolder[ "sticker"+this._parent.selectedStickerType+"Line"] you
will have a good reference to the selected sticker. And now that you have the
array, you can just use [ ] notation to access one of its elements:

_root.mc_stickerHolder[ "sticker"+this._parent.selectedStickerType+"Line"][ i ]

And then, you can access an elemen of THAT array:

_root.mc_stickerHolder[ "sticker"+this._parent.selectedStickerType+"Line"][ i
][6]

I hope that makes sense.


For the parent thing, see what is going on, add:

trace(this);
trace(this._parent);
trace(_parent);

see the difference!
Re: Addressing a variable - help please NSurveyor
10/15/2005 12:11:25 PM
Re: Addressing a variable - help please bderber
10/15/2005 1:13:43 PM
trace(this);
trace(this._parent);
trace(_parent);
produced the following:

_level0.mc_stickerHolder.mc_holder3
_level0.mc_stickerHolder
_level0


The third one is what confuses me - but maybe not. The action script for this
is in mc_stickerHolder - brought in with a #include. Could this be why it
references _level0 when you say trace(_parent). I would have assumed the
reference this was assumed - thus my thinking that trace(this._parent) would
return the same value as trace (_parent). What am I missing?


BTW your time and assistance is awesome.

bob
Re: Addressing a variable - help please NSurveyor
10/16/2005 12:00:00 AM
No problem.

If you don't use this before the path, then the path starts from the timeline
on which the code was PLACED. So in this case, the code is on mc_stickerHolder.
_parent would be the parent of mc_stickerHolder, _level0, not "this".


AddThis Social Bookmark Button