11 Replies Latest reply on Apr 26, 2010 9:04 AM by tlcheaves

    Load Flex Modules as SWF Element

    bugreport22

      Hello,

       

      im tying to load a Flex Modul with the SWF Element,

       

      this is my piece of code, I can load the module and talk to its properties, but the modul is not displayed. Maybe it is something wrong in the code

       

      override protected function processReadyState():void
                {
                     var loaderLoadTrait:LoaderLoadTrait = getTrait(MediaTraitType.LOAD) as LoaderLoadTrait;
                     
                     var content:DisplayObject = loaderLoadTrait.loader.content;
                     
                     if(content is IFlexModuleFactory) {
                          var content_onReady:Function = function (event:Event):void {
                               var factory:IFlexModuleFactory = content as IFlexModuleFactory;
                               var info:Object = factory.create() as Module;
                               info.urlRequest = "http://infotafel/xmlcontent/zwgmenueplan.xml";
                               addTrait(MediaTraitType.DISPLAY_OBJECT, new DisplayObjectTrait((info as DisplayObject),1920,1080));
                          }
                          content.addEventListener("ready",content_onReady);
                     } 
                     else { 
                          addTrait(MediaTraitType.DISPLAY_OBJECT, new DisplayObjectTrait(content));
                     } 
                }
      
        • 1. Re: Load Flex Modules as SWF Element
          bringrags Level 4

          Does your "ready" event handler ever get invoked?  Or is the problem that it gets invoked, but nothing gets displayed?  I don't think that anyone's tried to load a module with SWFElement, so you're probably breaking new ground.  (And can I ask why you want to do so?)

          • 2. Re: Load Flex Modules as SWF Element
            bugreport22 Level 1

            Hello Brian,

             

            the Ready handler gets invoked and I can use the methods and properties of the module in the Ready handler. The problem is that I cant see the displayObject on adding it as a displayobjectrait.

             

            After I get the SWFElement I wrap it as a DurationElement and ad it to my composition list. When the player starts to show the elements, he dont show my module but after the end of the duration the next elments are showed (other elements not flex module).

             

            The reason why I use this, is that I want to make a Digital Signage (Videos, Images, Weather Information etc. on LCD, Plasma Screens) Player with the OSMF. For that I create modules which can show for example the actual weather or upcomings events etc. on the LCD screens. The OSMF offers great possibilities to implement this.

            • 3. Re: Load Flex Modules as SWF Element
              bringrags Level 4

              Could you post (or email me - briggs at you know where) your module SWF?

              • 4. Re: Load Flex Modules as SWF Element
                bugreport22 Level 1

                I have email you the swf. Hope you can find a solution for that. That would be great!!!

                • 5. Re: Load Flex Modules as SWF Element
                  bringrags Level 4

                  Hmm, I didn't receive anything -- it might be our spam filter blocking attachments.  Can you post it to a server and send me the URL?

                  • 7. Re: Load Flex Modules as SWF Element
                    bugreport22 Level 1

                    Brian do you see any possibility to implement this case. It would help me much. Thanks for yours effort.

                    • 8. Re: Load Flex Modules as SWF Element
                      bringrags Level 4

                      I'm unable to load the SWF, I get a VerifyError (which usually means that it was compiled with a different set of classes than my own).  Which version of Flex did you use?  Are you able to get it to load and display if you compile it as a normal SWF, rather than a module?

                      • 9. Re: Load Flex Modules as SWF Element
                        bugreport22 Level 1

                        When I compile it as normal SWF and add create my CustomSWFElement for Flex SWFs adapted from the ChromeFlex Example

                         

                         

                        the Ready Handler fires and I get an Error that the swfRoot is null. Error #1009:

                         

                        public class CustomSWFElement extends SWFElement
                             {
                                  public function CustomSWFElement(resource:URLResource=null, loader:SWFLoader=null)
                                  {
                                       super(resource, loader)
                                  }
                                  override protected function processReadyState():void
                                  {
                                       super.processReadyState();
                                       
                                       // Flex SWFs load differently from pure AS3 SWFs.  For the former,
                                       // we need to wait until the applicationComplete event is
                                       // dispatched before we can access the SWF's API.
                                       if     (     swfRoot.hasOwnProperty("application")
                                            &&     Object(swfRoot).application == null
                                       )
                                       {
                                            swfRoot.addEventListener("applicationComplete", finishProcessReadyState, false, 0, true);
                                       }
                                       else
                                       {
                                            finishProcessReadyState();
                                       }
                                  }
                                  
                                  private function finishProcessReadyState(event:Event=null):void
                                  {
                                       // Flex SWFs expose their API through the root "application"
                                       // property, whereas pure AS3 SWFs expose their API directly.
                                       var theSwfRoot:DisplayObject = swfRoot.hasOwnProperty("application") ? Object(swfRoot).application : swfRoot;
                                       
                                       // Make sure the SWF has the expected API object.
                        
                                            
                                            if     (     swfRoot.hasOwnProperty("application")
                                                 &&     Object(swfRoot).application != null
                                            )
                                            {
                                                 // Re-dispatch our dimensions:
                                                 var displayObjectTrait:DisplayObjectTrait= getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;
                                                 displayObjectTrait.dispatchEvent
                                                      ( new DisplayObjectEvent
                                                           ( DisplayObjectEvent.MEDIA_SIZE_CHANGE
                                                                , false
                                                                , false
                                                                , null
                                                                , null
                                                                , 0
                                                                , 0
                                                                , displayObjectTrait.mediaWidth
                                                                , displayObjectTrait.mediaHeight
                                                           )
                                                      );
                                            }
                                  }
                                  
                                  private function get swfRoot():DisplayObject
                                  {
                                       var displayObjectTrait:DisplayObjectTrait = getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;
                                       return displayObjectTrait != null ? Loader(displayObjectTrait.displayObject).content : null;
                                  }
                                  
                                  override protected function processUnloadingState():void
                                  {
                                       super.processUnloadingState();
                                  }
                        
                             }
                        
                        • 10. Re: Load Flex Modules as SWF Element
                          bringrags Level 4

                          Probably the most efficient way to diagnose this is if you can file a bug with the source for a module SWF, and the source for an app that loads it.  I don't feel like I have enough info to provide much insight.

                          • 11. Re: Load Flex Modules as SWF Element
                            tlcheaves

                            We were having the same issue, but we are using Flash CS4 professional.  We created a custom SWFElement and wanted it to load in another swf that had it's own API.  We could hear the SWF playing and interact with its methods and properties, but we couldn't see anything.  After pounding our heads for a couple of days, we found that if we drew a shape on the stage our module showed up and behaved as expected.