1 Reply Latest reply on Oct 15, 2008 2:03 PM by Peter Lorent

    AS2 to AS3

    SiHoop Level 1
      I have 3 questions regarding my migration from AS2 to AS3.
      First, in AS2, I could generate variables on the fly. For example, I could write:
      var textHolder=new MovieClip
      textHolder.myVar=1
      I believe that doing this in AS3 requires me to extend MovieClip and to declare myVar in the sub-class. Is this correct?

      Second, in the code below, a text field (i.e. tf) is a child of a Movie Clip (i.e. textHolder), however, I don't seem to be able to control the text field though the chain textHolder.tf For example, if I try the following:
      trace("name="+e.target.tf.name), I get the error message: A term is undefined and has no properties.
      Is there another way to do this.

      Third, I notice that the following line is very important:
      textHolder.mouseChildren =false

      Removing it allows me to use the following trace statement:
      trace("name="+e.target.text)
      What is happening here?

        • 1. Re: AS2 to AS3
          Peter Lorent Level 2
          No, the MovieClip class is still dynamic so you can add properties. If you extend MovieClip but you dont declare your subclass dynamic, then you cannot add properties.

          To access a display list you need to use getChildByName or getChildAt. If you would add an instance name on your tf you can retrieve that tf using getChildByName(), see attached snippet (assuming you assign an instance name in the loop using tf.name = "tf";


          You need to read up on the target and currentTarget properties of events.