9 Replies Latest reply on Oct 10, 2008 1:23 PM by seileef

    Loading new SWFs in an SWFLoader

    seileef
      I'm trying to swap in and out different remote SWFs in an SWFLoader--This seems like it should be trivial, but I haven't been able to figure it out, and I've seen forum posts around that seem to be left unresolved, as well as a couple unresolved bug reports. I've tried things like .load(null), .source="", removeChild/addChild, and setting the SWFLoader variable to null and then creating a new SWFLoader assigned to that variable, but no luck with any of those.

      Does anyone have a way of doing this? I've attached the test code that I'm using. Any help would definitely be greatly appreciated.

      Much thanks,
      Robert
        • 1. Re: Loading new SWFs in an SWFLoader
          Level 7

          "robertseil" <webforumsuser@macromedia.com> wrote in message
          news:gc3dhf$70f$1@forums.macromedia.com...
          > I'm trying to swap in and out different remote SWFs in an SWFLoader--This
          > seems
          > like it should be trivial, but I haven't been able to figure it out, and
          > I've
          > seen forum posts around that seem to be left unresolved, as well as a
          > couple
          > unresolved bug reports. I've tried things like .load(null), .source="",
          > removeChild/addChild, and setting the SWFLoader variable to null and then
          > creating a new SWFLoader assigned to that variable, but no luck with any
          > of
          > those.
          >
          > Does anyone have a way of doing this? I've attached the test code that
          > I'm
          > using. Any help would definitely be greatly appreciated.

          Here's some really old code I have (read:kind of crap) that works:

          <?xml version="1.0" encoding="utf-8"?>

          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml"
          horizontalAlign="center" backgroundAlpha="1.0" height="100%" width="100%"
          verticalScrollPolicy="off" horizontalScrollPolicy="off" borderStyle="none"
          verticalAlign="bottom">
          <mx:Script>
          <![CDATA[
          import vo.MediaElement;
          import mx.effects.Fade;
          [Bindable]
          private var _img:String;
          [Bindable]
          private var _swf:String;
          [Bindable]
          private var _caption:String;
          private var _me:MediaElement;

          public function set mediaObject(me:MediaElement):void{
          if (me.imgSrc != ''){
          this.imgSrc = me.imgSrc;
          }
          if (me.swfSrc != ''){
          this.swfSrc = me.swfSrc;
          }
          this.caption = me.caption;
          _me = me;
          }
          public function get mediaObject():MediaElement{
          return this.mediaObject;
          }

          public function set imgSrc(img:String):void{
          _swf = '';
          _img = img;
          this.currentState = "isSwf";
          this.currentState = "";
          this.currentState="";
          }
          public function get imgSrc():String{
          return _img;
          }
          public function set swfSrc(swf:String):void{
          _img = '';
          _swf = swf;
          this.currentState="isSwf";
          }
          public function get swfSrc():String{
          return _swf;
          }
          public function set caption(cstr:String):void{
          _caption = cstr;
          }
          public function get caption():String{
          return _caption;
          }
          ]]>
          </mx:Script>
          <mx:VBox id="viewHolder" horizontalAlign="center" verticalAlign="bottom"
          height="100%" width="100%"
          verticalScrollPolicy="off" horizontalScrollPolicy="off" >
          <mx:Image id="imgCtrl" maintainAspectRatio="true"
          source="{'images/'+_img}"
          scaleContent="true"
          completeEffect="Fade"
          verticalAlign="bottom" horizontalAlign="center" />
          </mx:VBox>

          <mx:states>
          <mx:State name="isSwf">
          <mx:AddChild relativeTo="{viewHolder}">
          <mx:SWFLoader id="movie" source="{'movies/'+_swf}"
          maintainAspectRatio="true" horizontalCenter="0"
          verticalCenter="0" scaleContent="true" completeEffect="Fade"
          verticalAlign="bottom" horizontalAlign="center" />
          </mx:AddChild>
          <mx:RemoveChild target="{imgCtrl}" />
          </mx:State>
          </mx:states>
          <mx:Label id="captionLabel" text="{_caption}" color="#FFFFFF"/>
          </mx:VBox>


          • 2. Re: Loading new SWFs in an SWFLoader
            Peter Lorent Level 2
            Try attached code.
            • 3. Loading new SWFs in an SWFLoader
              seileef Level 1
              Thank you both for the suggestions--I wasn't able to get either of the code examples working though, unfortunately. The vo:MediaElement class in Amy's code couldn't be found (and I couldn't find much info on it with Google), and Luigi's code gave me the same behavior that I've been getting with a lot of the other methods: when you try to load the second SWF, the first one disappears but its audio continues, and the second SWF doesn't show up at all.

              I'm using mxmlc 3.1.0 build 2710 to compile these. Any ideas?

              Thanks again,
              Robert
              • 4. Re: Loading new SWFs in an SWFLoader
                Level 7

                "robertseil" <webforumsuser@macromedia.com> wrote in message
                news:gc5gf5$2lv$1@forums.macromedia.com...
                > Thank you both for the suggestions--I wasn't able to get either of the
                > code
                > examples working though, unfortunately. The vo:MediaElement class in
                > Amy's
                > code couldn't be found (and I couldn't find much info on it with Google),
                > and
                > Luigi's code gave me the same behavior that I've been getting with a lot
                > of the
                > other methods: when you try to load the second SWF, the first one
                > disappears
                > but its audio continues, and the second SWF doesn't show up at all.

                It's just a custom typed object I created. You could use your own instead,
                or just change the dataType to object.


                • 5. Re: Loading new SWFs in an SWFLoader
                  Peter Lorent Level 2
                  The code I posted switches the videos but the second video doesn't load because of a sandbox issue.
                  However, it doesn't solve the problem that the video/sound keeps running. To resolve that you need to stop all streams in the swf and since you don't have any access to the swf, you can't. That is, up till now I haven't found any solution to stop the streams without access to the loaded swf.
                  Why load the swf's anyway when you can just play the flv?
                  • 6. Re: Loading new SWFs in an SWFLoader
                    seileef Level 1
                    Amy, I tried changing the type to Object, but I got a blank application after compiling, with just the default background color and no components. I didn't want to invest too much time in debugging, since I wasn't sure if this method would indeed correct for the issue that Luigi is mentioning--being unable to stop the SWF's streams. Any ideas?

                    Luigi, I was considering just playing the FLVs, since that'd make things much easier, but for this application, it wouldn't really make sense to go without the UI components like the position bar, volume slider, etc., so that's why I need to play the SWFs.

                    I've seen some open source Actionscript FLV players (e.g. http://flv-player.net), but modifying those so that there's a way to communicate with one from Flex to stop its streams seems a bit of overkill. (I would also need to create similar functionality for loading and unloading mp3s in another player, which would just add to this extra work.)

                    It seems like this would be a common issue, with YouTube and Flash video being so popular. Does anyone know of a way to stop SWF's streams, or any other way around this?

                    -Robert
                    • 7. Re: Loading new SWFs in an SWFLoader
                      Level 7

                      "robertseil" <webforumsuser@macromedia.com> wrote in message
                      news:gcblj0$3il$1@forums.macromedia.com...
                      > Amy, I tried changing the type to Object, but I got a blank application
                      > after
                      > compiling, with just the default background color and no components. I
                      > didn't
                      > want to invest too much time in debugging, since I wasn't sure if this
                      > method
                      > would indeed correct for the issue that Luigi is mentioning--being unable
                      > to
                      > stop the SWF's streams. Any ideas?

                      You'd need to use an object with the properties the component expects.


                      • 8. Re: Loading new SWFs in an SWFLoader
                        Peter Lorent Level 2
                        Why not use the FLVPlayback component?
                        • 9. Re: Loading new SWFs in an SWFLoader
                          seileef Level 1
                          Sorry for the delay on this--things have been very busy recently. I'm going to use a FLVPlayback (thanks for the suggestion, Luigi--I'm a bit new to ActionScript and didn't know about this). However, if anyone has any ideas of how to resolve this SWFLoader problem, I'd definitely still be interested to see how to do it.
                          Thanks,
                          Robert