1 Reply Latest reply on Apr 24, 2009 10:42 PM by Flex harUI

    Trying to embed a symbol with a linkage .... not working :(

      Hello everyone,

       

      I am prety new to Flex so please bear with me if this is a dumb question I am just polishing up a flex air app for viewing and editting Collada models in Papervision and had my animated min/close buttons previously loaded in using Flash code:

       

       _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
                          
      var __appDomain:ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
      var __cls:Class;
                          
      if (__appDomain.hasDefinition("extraButtons.CloseButton")) {
           __cls = __appDomain.getDefinition("extraButtons.CloseButton") as Class;
           _closeButton = new __cls();
      }
                          
      if (__appDomain.hasDefinition("extraButtons.MinButton")) {
           __cls = __appDomain.getDefinition("extraButtons.MinButton") as Class;
           _minButton = new __cls();
      }
                          
      
      

       

      This allowed me to load in a library symbol with a linkage to a class for programmtic functionality. I noticed that when I export my release build though it has started not including my the buttons.swf though it retains the link in code as I can open package contents and drop it in there (obviously not an ideal solution , so I figured it was maybe a Flex thing wanting me to use embed instead but I can not seem to get it to work at all. Embedding symbols with no a straighforward default "export for actionscript" is easy enough but if I try to include a symbol with an attached class I get errors or in teh code below: a null reference on _closeButton and _minButton. Can this be done? (and yes my linkages are correct Thanks in advance for any help.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="60" height="34" creationComplete="init()">
           
           <mx:Script>
                <![CDATA[
                     import mx.core.UIComponent;
                     import extraButtons.MinButton;
                     import extraButtons.CloseButton;
                     
                     //creating loader so I can dynamically load flash assets
                     // protected var _loader:Loader = new Loader();
                     
                     
                     //embedding stuff the "flex" way
                     [Embed(
                     source="style/assets/graphics/buttons.swf",
                     symbol="extraButtons.MinButton"
                     )]
                     [Bindable]
                    public var _minEmbed:Class;
                    
                    [Embed(
                     source="style/assets/graphics/buttons.swf",
                     symbol="extraButtons.CloseButton"
                     )]
                     [Bindable]
                    public var _closeEmbed:Class;
                     
                     public var _closeButton:CloseButton = new _closeEmbed() as CloseButton;
                     public var _minButton:MinButton = new _minEmbed() as MinButton;
                     /////
      
      
                     //protected var _closeButton:CloseButton
                     //protected var _minButton:MinButton
                     protected var _uiClose:UIComponent = new UIComponent(); //need to be UI componenets to be able to add to stage
                     protected var _uiMin:UIComponent = new UIComponent(); // see above
                     
                     //event types
                     public static var MIN_PRESSED:String = "MP";
                     public static var CLOSE_PRESSED:String = "CP";
                     public static var MC_LOAD_DONE:String = "MCD";
                     
                     protected function init():void {
                          
                          setButtons();
                          
                          /* _loader.load(new URLRequest("style/assets/graphics/buttons.swf"));
                          _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); */
                     }
                     
                     //load minimize and close program buttons
                     protected function loadComplete(e:Event):void {
                          
                          /* _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
                          
                          var __appDomain:ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
                          var __cls:Class;
                          
                          if (__appDomain.hasDefinition("extraButtons.CloseButton")) {
                               __cls = __appDomain.getDefinition("extraButtons.CloseButton") as Class;
                               _closeButton = new __cls();
                          }
                          
                          if (__appDomain.hasDefinition("extraButtons.MinButton")) {
                               __cls = __appDomain.getDefinition("extraButtons.MinButton") as Class;
                               _minButton = new __cls();
                          } */
                          
                          setButtons(); //the animated min and close buttons
                     }
                     
                     protected function closeApp(e:Event):void {
                          _closeButton.removeEventListener(CloseButton.CLOSE_APP, closeApp); 
                          dispatchEvent(new Event(MinClose.CLOSE_PRESSED));
                     }
                     
                     protected function minApp(e:Event):void {
                          dispatchEvent(new Event(MinClose.MIN_PRESSED));
                     }
                     
                     protected function setButtons():void {
                
                          trace("setting buttons");
                
                          _closeButton.addEventListener(CloseButton.CLOSE_APP, closeApp);
                          _closeButton.width = 32;
                          _closeButton.height = 32;
                          _uiClose.addChild(_closeButton);
                          _uiClose.x = 26;
                          this.addChild(_uiClose);
                          
                          _minButton.addEventListener(MinButton.MINIMIZE_APP, minApp);
                          _minButton.width = 23;
                          _minButton.height = 23;
                          _uiMin.addChild(_minButton);
                          _uiMin.x = 0;
                          _uiMin.y = 7;
                          this.addChild(_uiMin);
                          
                          dispatchEvent(new Event(MinClose.MC_LOAD_DONE));
                          trace("minClose Load Done");
                     }
                ]]>
           </mx:Script>
           
      </mx:Canvas>