6 Replies Latest reply on Sep 7, 2011 10:39 AM by infeter

    creating uicomponents in loaded flash file

    infeter

      hello flex developers. i have a flex application and a flash swf file. flex application loads this flash file (which contains different overlays and some logic) and creates some flex components (UIComponents like Buttons and Labels) inside it in some places (in some overlays).

      i've tried various options with UIMovieClip, ContainerMovieClip, FlexContentHolder and FlexComponentKit but none of them works... after i add a UIComponent to loaded flash file - the component doesn't get initialized.

      also i tried examples with custom flash components embedded directly into flex application, which inherit from UIMovieClip and ContainerMovieClip, and they work fine inside flex application. but if i paste them in flash file and then load inside flex application - i again see UIComponents not being initialized...

      please help.

       

      here is my source code:

      flexLoadUITest.zip (loads flash file and then tries to create a button inside its custom flash component, but the button doesn't get initialized...) - http://www.megaupload.com/?d=J9Y28JX0

      flexUISpriteTest.zip (uses embedded flash custom components and displays button properly) - http://www.megaupload.com/?d=YF9BLCW0

       

      also here is my plain source code from not working flexLoadUITest:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" addedToStage="onStageAdded(event)">
         
          <mx:Script>
              <![CDATA[
                  import mx.controls.Button;
                  import mx.core.UIComponent;
                  import mx.flash.ContainerMovieClip;
                 
                  private var loader:Loader;
                  private var wrapper:UIComponent;
                  private var container1MC:ContainerMovieClip;
                  private var btn:Button;
                 
                  private function onStageAdded(event:Event):void{
                      trace("onStageAdded");
                      wrapper = new UIComponent;
                      addChild(wrapper);
                     
                      loader = new Loader();
                      loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
                      var loaderContext:LoaderContext=new LoaderContext();
                      loaderContext.applicationDomain=ApplicationDomain.currentDomain;
                      //loaderContext.securityDomain=SecurityDomain.currentDomain;
                      loader.load(new URLRequest("flash.swf"),loaderContext);
                  }
                 
                  private function onComplete(event:Event):void{
                      trace("onComplete");
                      loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onComplete);
                      loader.content.addEventListener(Event.ADDED_TO_STAGE,onContentAdded);
                     
                      wrapper.addChild(loader.content);
                  }
                 
                  private function onContentAdded(event:Event):void{
                      trace("onContentAdded");
                      loader.content.removeEventListener(Event.ADDED_TO_STAGE,onContentAdded);
                     
                      container1MC = loader.content["container1_mc"];
                      trace("container1MC is " + container1MC);
                     
                      btn = new Button();
                      btn.label="deniska";
                      btn.width=btn.height=100;
                      btn.addEventListener(Event.ADDED_TO_STAGE,onBtnAdded);
                     
                      container1MC.content=btn;
                      //container1MC.addChild(btn);
                  }
                 
                  private function onBtnAdded(event:Event):void{
                      trace("onBtnAdded");
                      btn.removeEventListener(Event.ADDED_TO_STAGE,onBtnAdded);
                  }
              ]]>
          </mx:Script>
         
         
      </mx:Application>

        • 1. Re: creating uicomponents in loaded flash file
          infeter Level 1

          wanted to make it even clear. after i do this:

          container1MC.content=btn;

          "btn" doesn't get initiliazed and function "onBtnAdded" not executed at all...

          • 2. Re: creating uicomponents in loaded flash file
            Flex harUI Adobe Employee

            UIComponents must be parented by other UIComponents.  You might be able to

            hack around that, but it isn't really supported.

            1 person found this helpful
            • 3. Re: creating uicomponents in loaded flash file
              infeter Level 1

              thank you for helping me. i see in my case container1MC is a custom flash component which inherits mx.flash.ContainerMovieClip, i thought it's the same as UIComponent... simply if i use this component as embedded swc in flex application - it works (you can see flexUISpriteTest project), but if i add this component to flash, then load this flash via Loader and then try to create some button in it - it doesn't get displayed (you can see flexLoadUITest). what i am doing wrong? please explain.

              • 4. Re: creating uicomponents in loaded flash file
                Flex harUI Adobe Employee

                It is likely that the flash SWF wraps the component with other display

                objects and breaks some chain of assumptions.  Trying to pass Flex

                components across a Loader boundary is unlikely to work.

                1 person found this helpful
                • 5. Re: creating uicomponents in loaded flash file
                  infeter Level 1

                  got it, thanks. basically i don't want to spend time hacking UIComponents. to tell the truth i already have a custom UISprite logic to work with UIComponents, but it still using hacks... maybe you can recommend me some unified/modern way how to be able creating flex components dynamically and work with them in loaded swf files? simply these swfs are created by designers who work in Flash Professional. they draw there different animations, paste various assets and map some "content" for future dynamic components. of course i can create there non flex components, add sprites to these "content" areas, but i want flex UI components to appear there because they need to work close with system's core and various air/flex features. as i see flex component kit gives me ability to use some separate custom components created in flash with a small additional conversion of them. but these are all separate components, and i need to work with loaded swf file. are there any recommendations or guidelines for this direction? or maybe there is simply a tool/class that can be used/loaded into these swfs and make them fully capable for flex usage after loading?

                  • 6. Re: creating uicomponents in loaded flash file
                    infeter Level 1

                    i want to add what i tried to achieve with this flex component kit. i thought i will be sending these designers some custom components (a simply one component which they will naming in its properties panel) which they will be adding from Flash Professional's components library and placing in different places on a stage. and then after they publish and send me their swfs - i will be simply loading them and working with these "dynamic areas" (custom components) - placing and generating UI components there, adding containers etc...

                    now i understood that i can use flex component kit in other direction - only if they will be sending me seperate parts of these flas. then i will need to map areas in them, convert to flex components, attach them as swcs to flex application, collect everything in one place, create same fla structure in flex application's mxml and use. that's absolutely not suitable process for all of us...