4 Replies Latest reply on Nov 25, 2006 9:16 AM by Peter Lorent

    OOP Help

    crispymuscat Level 1
      Please could someone explain to me as clearly as possible how I instantiate an object in this situation

      i have

      holder.createEmptyMovieClip("holder",getNextHighestDepth());

      i want to instantiate a another object (from a custom built class which extends the Movieclip class)
      within this holder level.

      this is where i am confused and asking for guidance:

      var _root.holder.namevariable:CustomObject= new CustomObject(); // doesn't work--seems trashy

      or should it be

      var namevariable:CustomObject= new _root.holder.CustomObject(); // doesn't work either--seems trashy


      because if i just say,

      var namevariable:CustomObject= new CustomObject();

      the object is not sitting in the holder container, therefore the stacking order is wrong





        • 1. Re: OOP Help
          Peter Lorent Level 2
          When you extend the MovieClip Class there needs to be a one-on-one relationship with a movieclip in the library which is ilnked to the class using the 'Linkage' option. You use attachMovie() to instantiate a new instance.
          ->holder.createEmptyMovieClip("holder",getNextHighestDepth());
          ->holder.attachMovie("CustomObject","new_instance_name",depth);
          target the CustomObject with:
          holder.new_instance_name

          CustomObject is the name you provide in the 'Linkage' identifier.
          • 2. Re: OOP Help
            crispymuscat Level 1

            Thanks for the reply---i hope i understand the display objects , but how do you target other objects such as arrays etc and is it necessary to be concerned with where they are instantiated, ie for the sake of being consistent, i would like to keep all objects within the same container, so that i dont have display objects in one container and related array objects sitting on in the _root.
            So if i am wanting to declare a new variable within the _root.holder. ----container,
            what is the correct form for this
            var bing:Array = new Array(); how do i keep the array within the holder container
            or
            var _root.holder.bing:Array = new Array();

            • 3. Re: OOP Help
              Level 7

              Thanks for the reply---i hope i understand the display objects , but how do
              you target other objects such as arrays etc and is it necessary to be concerned
              with where they are instantiated, ie for the sake of being consistent, i would
              like to keep all objects within the same container, so that i dont have display
              objects in one container and related array objects sitting on in the _root.
              So if i am wanting to declare a new variable within the _root.holder.
              ----container,
              what is the correct form for this
              var bing:Array = new Array(); how do i keep the array within the holder
              container
              or
              var _root.holder.bing:Array = new Array();



              • 4. Re: OOP Help
                Peter Lorent Level 2
                Attached an example of a class that extends the MovieClip Class. On the stage (or use attachMovie() to instantiate a new instance) I have a box with an instance name 'box_mc'. The mc is linked to the class in the library using the Linkage option and the AS2 class is 'Box'. Inside the box mc I have a text_mc and in the text_mc is a dynamic text field with an instance name 'test_txt'.

                The class fade in the box and then sets the text for the text field. When that is done it instructs the _root to go to and stop on frame 5. There I have code on the timeline. Using the instance name of the box I can call a public method of the class:
                box_mc.doRotate();