Skip to main content
Known Participant
April 20, 2006
Answered

Trying to access a specific movie clip with a string

  • April 20, 2006
  • 11 replies
  • 822 views
Ok, what I am trying to do is create as many movie clips as I need and then access those movie clips using string values. These string values are stored in an array and coincide with a given movie clips instance name. Check out the following code:


I think my problem is that Flash is trying to call movie clip methods on a string instance. I'm not sure how to type cast in Flash, or even if it is possible, but how would I access the strings as movie clips?
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Newsgroup_User
DuhChamp,

> I think my problem is that Flash is trying to call movie
> clip methods on a string instance.

Bingo.

> I'm not sure how to type cast in Flash, or even if it is
> possible, but how would I access the strings as movie
> clips?

Use eval() or the array access operator, []. Details here ...

http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


11 replies

April 20, 2006
Of course you can't set the properties in your changed variant, because it's an array of strings. So what good would the _x be for a string?
Your variant loads a clip, because the target parameter being a string is ignored. In the example with temp_mc it's an object, so it's not being ignored. You probably are loading the image, but don't see it, because something else is wrong.
Trace the return code on the mImageLoader.loadClip function call.
By the way, for me this line is dubious:
cards.push("holeCard0" + this.m_CardsDealt++); I know the ++ should increase the Number variable after being used, but you are constructing a string there. Did you ever trace your movieClip names? Maybe there's something wrong there.
I would definitely go with the temp_mc variant. In general, this works. I have used it successfully. But you need to update your depth counters, and CardsDealt, of course.
Good luck
Wolf
April 20, 2006
I would not push string variables but direct references to the created movieClips, like so:

temp_mc = _root.createEmptyMovieClip....
then
cards.push(temp_mc);

rest unchanged (and I mean the original code, not the one with eval)
DuhChampAuthor
Known Participant
April 20, 2006
I tried the temp_mc = _root.createEmptyMovieClip.... method, but it doesn't seem to work. I don't even get the picture to load anymore.
DuhChampAuthor
Known Participant
April 20, 2006
Got it working fellas. Thanks for the help... It was all a matter of scope.. I added a definition of the scope as a member variable of my class, and it works like a charm. Thanks again guys.
April 20, 2006
Can you repost please, with code attachment. I'll have a look.
Oops, sorry, I see you have already. Will be back in a few moments...

April 20, 2006
You need to decide whether you want holeCards or holdCards :-)
Is it BlackJack?
Also, please use code attachment, otherwise all your [array indices] go awry, and code becomes very difficult to read.
Good luck
Wolf
DuhChampAuthor
Known Participant
April 20, 2006
I fixed the typo, still no luck.
DuhChampAuthor
Known Participant
April 20, 2006
Ok, now I get at least one of the images to load to a movieClip (I see the image that I should see), but I still cannot modify the movie clip properties.

The following lines of code give me:

undefined X VALUE OF MOVIE
false

in my output panel.

DuhChampAuthor
Known Participant
April 20, 2006
I've also tried this....



for(var i = 0; i < this.m_CardsDealt; i++)
{
//var holder:MovieClip = eval(cardArray );
var holder:MovieClip = this[cardArray
];
_root.holder._x = 200;
//_root.cardArray ._x = 200;
holder._y = 250;

mImageLoader.loadClip("../Flash Project/Images/Cards/" + this.getDeck()
.getFile(), holder);
trace(this.getDeck() .getFile());
trace(_root.holder._x + " X VALUE OF MOVIE");
}


And also this....



cards.push(this["holeCard0" + this.m_CardsDealt++]);
DuhChampAuthor
Known Participant
April 20, 2006
My code keeps getting messed up when I transfer it to these boards, but after every place i use an array that needs an index, I have it . So where it sayssomething like cardArray._x, in my code it says cardArray [ i ]._x;
Newsgroup_UserCorrect answer
Inspiring
April 20, 2006
DuhChamp,

> I think my problem is that Flash is trying to call movie
> clip methods on a string instance.

Bingo.

> I'm not sure how to type cast in Flash, or even if it is
> possible, but how would I access the strings as movie
> clips?

Use eval() or the array access operator, []. Details here ...

http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."