A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Accessing a MC via a variable string reference

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    567

    Accessing a MC via a variable string reference

    Code:
    var possibleName:String = "mcIReallyWantThisClip"; 
    possibleName.addChild(mcChildClip);
    Just wondering if there's an easy way to add the child to the "mcIReallyWantThisClip" rather than a clip called "possibleName"...

    (I've used getDefinitionByName, but that seems to wants me to create a new instance of mcIReallyWantThisClip.)

  2. #2
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    Right now what you are doing is trying to call the addChild Method of a string... That obviously doesn't work. From your code I am assuming you already have a MovieClip called mcIReallyWantThisClip created and on the stage somewhere. In that case you need to do the following:

    Code:
    var possibleName:MovieClip = getChildByName("mcIReallyWantThisClip"); 
    possibleName.addChild(mcChildClip);
    JA

  3. #3
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    No,what he was trying to do is create a clip and use the string possibleName to reference it
    PHP Code:
    var possibleName:String "mcIReallyWantThisClip"
    this[possibleName] = new MovieClip();
    addChild(this[possibleName]);
    this[possibleName].10;

    trace(this.mcIReallyWantThisClip.x);//10 

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    567
    Cimmerian, that's exactly what I wanted, thank you! Sorry I wasn't more clear, JHarlequin.

    Thanks again.

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