6 Replies Latest reply on Jun 21, 2010 6:37 AM by Ben Danis

    External Swfs with flex components

    Ben Danis

      I am having troubles with using external UIComponents and the systemManager property.

       

      I have external screens that are based as UIComponents.  i compile each screen individually as a swf using the ANT tool.  This generates all my swf files externally.

       

      I then have a main file that loads those screens once needed.  The screen that i load creates a canvas within itself and uses mx components into it, such as <mx:Buttons>.  The problem is that when i click on that button, i get a systemManager == null error.

       

      What is the best way to have external screens and have them load within my main UIComponent?  I tried using modules, but couldn't get them to run properly and the swf files generated were huge! (600K a piece).

       

      I am using flash builder 4 and decided to forego using Spark since it's a tight timeline and i don't have time to learn a whole new method of approach.

       

      thanks in advance

        • 1. Re: External Swfs with flex components
          Flex harUI Adobe Employee

          Modules are the way to go.  Make sure you use the module project or set the

          compile optionsn appropriately.  It would be rare for them to be 600K each.

          Look at the link-reports to see why.

          1 person found this helpful
          • 2. Re: External Swfs with flex components
            Ben Danis Level 1

            thanks, i'm trying to use the moduleLoader at the moment and the READY event is never caught unless i put a break point before the loading is complete.

             

            any idea why? do i need to add the module Loader in the proper container?  Is it like adding an AS2 Component, meaning it can't exit its sandbox?

            • 3. Re: External Swfs with flex components
              Flex harUI Adobe Employee

              Not sure why you're not getting the READY event.  Do you get the PROGRESS,

              COMPLETE and INIT events?

               

              Make sure the classes in the module are not already linked into the main

              app.  Use link-report to verify.

              • 4. Re: External Swfs with flex components
                Ben Danis Level 1

                here's an excerpt of my class
                public class ModulesLoader extends EventDispatcher implements IAssetLoadingHelper
                    {
                        private var _url:String;
                       
                        private var _loader:ModuleLoader;
                       
                        private var _data:Object;
                       
                        public function ModulesLoader(aURL:String)
                        {
                            _url = aURL;
                           
                        }
                        public function startLoading():void {
                            _loader = new ModuleLoader();
                           _loader.addEventListener( ModuleEvent.READY, _onLoadComplete );
                              _loader.addEventListener( Event.COMPLETE, _onLoadComplete );
                            _loader.addEventListener( ProgressEvent.PROGRESS, _onLoadProgress );
                            _loader.addEventListener( IOErrorEvent.IO_ERROR, _onLoadError );
                            _data = _loader;
                           
                            _loader.loadModule(url);
                        }
                        public function destroy():void {
                            if( _loader!=null ) {
                                _removeListeners();
                                _loader = null;
                            }
                        }
                        public function get url():String { return _url; }
                        public function get data():* { return _data; }
                        public function unload():void {
                            try {
                                _loader.unloadModule();
                            } catch (e:Error) {
                                ;
                            }
                        }
                        private function _onLoadComplete( aEvent:Event ):void {
                           
                            _removeListeners();
                            _loader.addEventListener(Event.ENTER_FRAME, _contentCreated);
                        }
                        private function _contentCreated (e:Event):void {
                            _loader.removeEventListener(e.type, _contentCreated);
                           
                            dispatchEvent( new Event(Event.COMPLETE) );
                            destroy();
                        }
                       
                       
                        private function _onLoadProgress( aProgressEvent:ProgressEvent ):void {
                           
                            dispatchEvent( aProgressEvent.clone() );
                           
                        }
                       
                       
                        private function _onLoadError( aIOErrorEvent:IOErrorEvent ):void {
                           
                            _removeListeners();
                           
                            dispatchEvent( aIOErrorEvent.clone() );
                           
                        }
                       
                       
                        private function _removeListeners():void {
                           
                            _loader.removeEventListener( ModuleEvent.READY, _onLoadComplete );

                            _loader.removeEventListener( Event.COMPLETE, _onLoadComplete );
                            _loader.removeEventListener( ProgressEvent.PROGRESS, _onLoadProgress );
                            _loader.removeEventListener( IOErrorEvent.IO_ERROR, _onLoadError );
                           
                        }
                    }

                 

                i even added a component within the module that dispatches an Event.COMPLETE bubbling and it's not capturing it, tried adding an enter_frame as well to let it process. still nothing...

                • 5. Re: External Swfs with flex components
                  Ben Danis Level 1

                  I'm not using ant anymore actually, having created modules generates the swfs whenever i need it.  So i don't have the link Report anymore, i used to be able to see all the classes that were in a swf, like in Flash Builder, but i don't see it anymore.

                  • 6. Re: External Swfs with flex components
                    Ben Danis Level 1

                    I have made sure to add the loader to the UIComponent container that it should be displayed in and the events for ModuleEvent.READY are now being caught