A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [CS3]Any ideas to instantiate library symbols dynamically?

  1. #1
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229

    [CS3]Any ideas to instantiate library symbols dynamically?

    In Flash 8 I used dynamic linkages to instantiate symbols quite often, i.e. / 'symbol_'+i / can load ordered linkage symbols for 'symbol_0', 'symbol_1', 'symbol_2'...

    Now in Flash CS3, no linkage any more but they have to be a class name such as 'TreeHouse_0' class for a 'Tree House 0' symbol. They can not be instantiated with / new ['TreeHouse_'+i]() / or so. Any one have some ideas?

    Thanks.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is an example. You can give variable names.


    for (var count:int = 0; count <= 10; count++)
    {
    var myVar:MovieClip = new MovieClip ();
    myVar.name = "myVar_"+count02;
    myVar.y = count02*myVar.height;
    this.addChild (myVar);
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229
    Thanks Cancerinform. Though I'm looking for idea of dynamic 'linkage' (custom class in CS3) but not dynamic instance name.

    For example in AS2, it was:

    var i:Number;
    for(i=0; i<10; i++)
    this.attachMovie("symbol_"+i, "s"+i, this.getNextHighestDepth());

    In CS3 the first parameter is changed to a class name which cannot create dynamically. But to do this way it sucks:

    var s0=new symbol_0();
    s0.name = 's0';
    var s1=new symbol_1();
    s1.name = 's1';
    ...

  4. #4
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    Hi, I had a similar problem and I solved it using code similar to this. I hope it helps.

    var classReference:Class = getDefinitionByName("symbol_"+i) as Class;
    var newClip:MovieClip = new classReference()
    stage.addChild(newClip)

  5. #5
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229
    Good point. Thanks Cortana.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center