views:

1796

answers:

1

Hi All!

I am creating a flash app that reads an XML file from a specific source. The XML file contains maximum 5 nodes, each containing a name,description and an image URL.

To represent data in each node i created a movie clip that contains another movie clip (to load image from url), a short dynamic textbox (for name) and a long dynamic textbox (for description).

In code i can access them just by -

new_mc.myname.text = "some text"; new_mc.image_mc.loadMovie("path_to_image");

This is fine as long as i use duplicateMovie() and use the instance name "new_mc"

my problem starts with the loop ...

Since i can read the XML nodes in for loop i thought i would just create the movie clip dynamicaly and access all objects inside it.

So, in the for loop i created an instance like -

 myform.duplicateMovie("new_mc"+i,i)

but i can not access the movie created with instance name = "new_mc" + i

how can i access the newly created movie clip instance like new_mc0,new_mc1,new_mc3,...

so that i can access objects inside it?

May be the solution is simple enough for you since you have experiance enough, but i am a newbie here requesting help :)

good day to all!

A: 

I did almost never use the duplicateMovie() method in AS2 but if that's your choice you can access them like this :

this["new_mc"+i];

otherwise a good practice is to always reference your instances to have better control over it :

var forms:Array = new Array();

for(...)
   forms[i] =  myform.duplicateMovie("new_mc"+i,i);

...

forms[2].myname.text = "hello";
  • First thing I would advice you using AS3, but there may be a reason you still use AS2...
  • Second thing, in AS2 to create instances it's somehow smoother to define MovieClips in the library, and use the attachMovie(); method to create instances.
Theo.T