3 Replies Latest reply on Mar 24, 2008 9:00 AM by injpix

    OO explanation with AS3.0

    injpix Level 3
      Trying to get familiar with Flex and AS3.0 by building an interactive multimedia instruction (IMI) that will be driven by an XML file, I am perplexed on the following issues:

      The first issue: I have a class named Template, which I want it to act like a custom Canvas component. The Template class always creates a Canvas instance and then starts adding the built-in components (Buttons, Labels) in it depending on the XML file. I can’t seem to create a Button instance in Template unless it extends the mx.controls.Button class. And then I have to override the properties of the Button class.

      Why is that? Why can’t I just have Template create a Button instance without extending, I was able to do this in AS2.0.



      The second issue: If the first issue exists, how can I have my custom class, Template, to extend multiple built-in classes since it needs multiple controls and containers? I am thinking a custom Interface would be ideal; however I don’t have any experience with Interfaces.

      thanks
        • 1. Re: OO explanation with AS3.0
          Gregory Lafrance Level 6
          I would think you could import mx.controls.Button and other controls, and then just create then in your Template class.
          • 2. Re: OO explanation with AS3.0
            injpix Level 3
            I seem to be getting closer to a solution after reading peterent’s reply on commitProperties() and after searching the livedocs on ‘Implementing the component’
            Still appreciate any comments.
            • 3. Re: OO explanation with AS3.0
              injpix Level 3
              The livedocs are helping me out, again!
              I am able to get the ‘Creating the ModalText component’ from the livedocs (Flex 2.01) working on my machine, however when I try to modify it slightly it doesn’t work. All I am trying to do is to have text_mc and mode_mc to be nested in a canvas instance. After compiling, all that renders on stage is a vertical line. I simply modified only the createChildren() as below:


              override protected function createChildren():void {
              super.createChildren();

              var template_mc:Canvas = new Canvas();

              // Create and initialize the TextArea control.
              if (!text_mc)
              {
              text_mc = new TextArea();
              text_mc.explicitWidth = 80;
              text_mc.editable = false;
              text_mc.text= _text;
              text_mc.addEventListener("change", handleChangeEvent);
              template_mc.addChild(text_mc);
              }

              // Create and initialize the Button control.
              if (!mode_mc)
              { mode_mc = new Button();
              mode_mc.label = "Toggle Editing Mode";
              // If you do not have skins available,
              // comment out these lines.
              mode_mc.setStyle('overSkin', modeOverSkinName);
              mode_mc.setStyle('upSkin', modeUpSkinName);
              mode_mc.setStyle('downSkin', modeDownSkinName);
              mode_mc.addEventListener("click", handleClickEvent);
              template_mc.addChild(mode_mc);
              }
              }



              Any suggestions?