A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: setting vars in instantiated mc's

  1. #1
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    setting vars in instantiated mc's

    Hi,

    I use this to create new instances of a movieclip:

    Code:
    var myOnStageClip:MovieClip = this.text_mc;
    var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));
    var myDuplicateClip:MovieClip = new myLinkage();
    Setting properties of components inside this mc works fine:

    Code:
    myDuplicateClip.text1.text = "something";
    However there are some vars in this mc on the the first frame, something like:

    var myurl:String;

    When I set this var in the code after the mc is duplicated:

    Code:
    var myOnStageClip:MovieClip = this.text_mc;
    var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));
    var myDuplicateClip:MovieClip = new myLinkage();
    
    myDuplicateClip.text1.text = "something";
    
    myDuplicateClip.myurl = "http://www......";
    trace(myDuplicateClip.myurl) returns the contents of the var correctly.

    However, when duplicating the movie clip, another movie clip is also duplicated with a var referencing the first duplicated movie clip:

    Code:
    var myOnStageClip1:MovieClip = this.drag_mc;
    var myLinkage1:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip1)));
    var myDuplicateClip1:MovieClip = new myLinkage1();
    
    myDuplicateClip1.source_mc = myDuplicateClip;
    The second movieclip has an eventlistner:
    Code:
    function MouseDown(event:MouseEvent):void{
        trace("url" + source_mc.myurl + "   " + source_mc.text1.text);
    }
    The trace comment outputs:
    Code:
    url: something
    The var myurl in souce_mc is empty!

    I hope I have explained the problem clearly. Does anyone have an idea of what is going on here?

    Thanks,
    Raoul
    Last edited by raoul; 10-29-2010 at 09:39 AM.

  2. #2
    Senior Member
    Join Date
    Feb 2000
    Posts
    226
    I stripped the fla down to the 2 mc's, you can download it here:

    http://www.andasoft.com/temp/varsProblem.zip

    You will see the 2 mc's that will be instantiated at the top outside the stage area. When running the fla the 2 mc's will be instantiated and these instances will be visible on the stage. This code is in frame 1 in the root. In this code you will also see 2 lines that will change the text of the textfield and the "myurl" string var of the mc named "text_mc".

    Now click on the "click me" mc, which is the other instantiated mc. This will output the text in the instantiated "text_mc" textfield and the value of the "myurl" var. Note that the output of the textfield is indeed the updated text and the value for "myurl" is empty!?

    Does this make sense to anyone?

    Thanks,
    Raoul

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