2 Replies Latest reply on Feb 10, 2010 7:10 AM by david.t.lanton

    My .as class not working in flex project

    david.t.lanton Level 1

      I have a .as file that extends Sprite and renders visual elements on the screen

       

      package actions {

       

           import flash.display.Sprite;

       

           public class MyAction extends Sprite {
                public function MyAction () {

                }

           }
      }

       

      I'm trying to include it as part of a Flex project, to add those shapes to my stage.

       

      I've created a package called actions under src and saved the .as file there.

       

      Because it renders visual elements, I thought I could wrap it as a UI component and add that to the stage.So I created a new .as file MyUIComp.as that basically looks like this:

       

      package actions {

       

           import actionscript.MyAction; 
           import mx.core.UIComponent;

       

           public class MyUIComp extends UIComponent {


                 private var myAction:MyAction;

       

                public function MyUIComp() {

                     myAction = new MyAction();

                }

           }
      }

       

       

      then in my main mxml, I'm adding it to a UIComponent like this

       

      <mx:UIComponent      id ="actionLocation" />

       

      and in the script section, wiring it:

       

      private function init():void {    
           var actionToStage:MyUIComp = new MyUIComp();
           actionLocation.addChild(actionToStage);

      }

       

      I don't get any errors, but nothing shows up on the stage either.

       

      Can someone be kind enought to tell me what I maybe doing wrong. I'm a bit new, so maybe I'm missing something obvious.

       

      Thanks,

      David

       

      P.S. Ideally I wouldn't create a wrapper MyUIComp class to make my class extend  UIComponent. I would use the original class like this:

       

           import flash.display.Sprite;

           import mx.core.UIComponent;

       

           public class MyAction extends Sprite UIComponent {

       

           }

       

      but this double extends doesn't seem to work