5 Replies Latest reply on Jun 18, 2010 12:52 PM by John Hall

    Basic SWFLoader question

    John Hall Level 4

      Reducing my code down to a simply clip, I have something along the lines of the following:


      import mx.managers.SystemManager;


      public var container1:SystemManager;


      private function initPic1():void{
          container1 = SystemManager(pic1.content);


      <mx:SWFLoader includeIn="mainDisplay"


      As soon as initPic1 is invoked, I get a coercion failure message : Type Coercion failed: cannot convert outsideToLobby_fla::MainTimeline@51a8f061 to mx.managers.SystemManager.


      Why fla type? More importantly, do you see a syntax problem that would cause the issue?

        • 1. Re: Basic SWFLoader question
          Flex harUI Adobe Employee

          Most SWFs built from a FLA do not have a SystemManager as the root.

          • 2. Re: Basic SWFLoader question
            BhaskerChari Level 4

            Hi John Hall,


            The "pic1.content" will get you a reference to the Flash SWF MainTimeline but not the SystemManager(By assuming the SWF loaded is a Flash SWF).


            You can try out the below code without Casting the content:


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
                  import mx.utils.StringUtil;
                  import mx.controls.Text;
                  import flash.net.navigateToURL;
                import flash.net.LocalConnection;                
                 import mx.controls.Alert;   
                 private var conn:LocalConnection;
                 private var loadedSWFMainTimeline:*;
                    public function onSWFLoadComplete():void {
                         //loadedSWFMainTimeline gets you a reference to the Flash SWF MainTimeline
                loadedSWFMainTimeline = swfLoader.content;
                var _button:SimpleButton = loadedSWFMainTimeline.flash_button as SimpleButton;
                public function onMCButtonClick(event:MouseEvent):void {
                Alert.show("Flash Button Clicked");
                 <mx:SWFLoader id="swfLoader" source="assets/lifeinsurance.swf" complete="onSWFLoadComplete();"/>
                 <mx:TextArea id="output" width="221" height="221" wordWrap="true"/>


            Note: In the above code flash_button is the button instance of the Flash SWF.

            If this post answers your question or helps, please kindly mark it as such.


            Bhasker Chari

            • 3. Re: Basic SWFLoader question
              John Hall Level 4

              I must be so overlooking something basic. What I've gone to is a swfloader. If I hard-wire the source in the mxml, all works fine. If I use actionscript (reduced to bare minimum) in the same component, I can not get the swf to load.


              In short, the SWFLoader name is "myMovie" (as of this hour ;-)


              If I debug, the source is there as a String, which seems legal since it's typed as an Object including string or MC or whatever. However, the content of the SWFLoader remains null. The complete event (hard-wired in the mxml component or using ActionScript with an eventListener) never fires.


              I've tried setting the source with movieSource bindable. In the component it reads


              <mx:SWFLoader id="myMovie"
                                source = "{movieSource}"
                                toolTip="Click on front entrance to navigate there."
                                click="trace('myMovie here');startCutAnimation()"/>


              initMovie never fires.


              I've tried actionscript with  


              and the actionscript snipped that is invoked is:


              movieSource  = "resources/assets/" + movie + ".swf"; (yes it exists and is spelled correctly as it works when hard-wired)
              myMovie.source = movieSource;


              complete event never fires


              I've tried myMovie.load(movieSource) and myMovie.load("resources/assets/outsideToLobby.swf";


              The source is always correct when I debug but no content.


              I've tried invalidating properties, invalidating displaylists, invalidating my attitude and non of those have an effect. I must be missing a typo or a simple principle. Thanks for any help.

              • 4. Re: Basic SWFLoader question
                BhaskerChari Level 4

                Hi John Hall,


                Try to give the path ...correctly, if you assign the source correctly to the SwfLoader then the complete event should defenitely get called...


                movieSource  = "resources/assets/" + movie + ".swf";


                what value is there in "movie" variable in above line of code....


                Once try giving the source directly wothout using the varible....However it makes no difference but I suspect that movie variable is not being populated correctly..




                Bhasker Chari

                • 5. Re: Basic SWFLoader question
                  John Hall Level 4

                  Thanks for taking the time to try to answer. I found the issue was unrelated to the component. I'm using the Mate Framework and I was dispatching events to a new instance of the class each time instead of the instance that was already created. Somedays, I can spend 3 hours and finally find the mis-spelling but it always seems to help to voice the question because it makes me question the logic of the question.


                  Thanks again.