4 Replies Latest reply on Apr 15, 2008 6:37 AM by Handycam

    Control a SWF from Flex?

    Handycam Level 1
      I have a flex app with a view stack that has some of it's children SWFLoaders.

      For example "page 2" of the view stack is an interactive SWF from flash cs3. It loads and works perfectly, but how do I stop it and reset it from Flex, as in when the user changes view stack views?

      The SWF is happily playing, but the user goes back to "page 1" of the VS, the SWF on page 2 is still playing its audio.

      How do I control the SWF?
        • 1. Re: Control a SWF from Flex?
          ntsiii Level 3
          You can access public members of the loaded swf through the SWFLoader.content property.

          Tracy
          • 2. Re: Control a SWF from Flex?
            Handycam Level 1
            This is what I've tried, based on searching for SWFLoader.content:

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

            <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%">
            <mx:Script>
            <![CDATA[
            import mx.managers.SystemManager;

            public function resetFlash():void {
            loadedSM.application.resetAll();
            }

            [Bindable]
            public var loadedSM:SystemManager;

            // Initialize variables with information from
            // the loaded application.
            private function initNestedAppProps():void {
            loadedSM = SystemManager(equipFlash.content);
            }
            ]]>
            </mx:Script>

            <mx:SWFLoader id="equipFlash" source="assets/equipment.swf" width="746" height="550" creationComplete="initNestedAppProps();"/>

            </mx:Canvas>


            And the line "loadedSM.application.resetAll();" is flagged as an error. "resetAll" is the name of the public function I'm trying to trigger.
            • 3. Re: Control a SWF from Flex?
              slaingod Level 1
              You should find examples of how to do this if you search these forums for SWFLoader.

              There are 2 different methods, 1 for if the SWF is just a Flash SWF, another for embedding a Flex app inside of another Flex app. You should only need to use 'application' and SystemManager for embedding other Flex apps. Otherwise you should use content, set it to a MovieClip, then you can call my_swf.gotoAndPlay(2); for instance, or my_movie.custom_method();

              Quick search should find examples by mysefl and many others.
              • 4. Re: Control a SWF from Flex?
                Handycam Level 1
                I found an old post that helped, with a simple change. In the interest of helping others who find this thread, here's what worked for me:

                In my "page 2" component:
                <mx:Script>
                <![CDATA[
                import mx.controls.SWFLoader;

                private var movie_clip:MovieClip;
                private var myLoader:SWFLoader = new SWFLoader();

                private function init():void {
                myLoader.addEventListener(Event.INIT,loadHandler);
                myLoader.load("equipment.swf");
                this.addChildAt(myLoader,0);
                }

                private function loadHandler(e:Event):void{
                movie_clip= e.target.content;
                }

                public function pp():void {
                movie_clip.remotePause();
                }

                ]]>
                </mx:Script>

                And then, in the master app:

                <mx:ViewStack id="mainVS" width="746" height="550">
                <comp:Intro id="intro" label="Introduction"/>
                <comp:Equipment id="eq" label="Equipment" show="eq.pp()" hide="eq.pp()" />
                <comp:VideoPlayer id="v" label="Video" show="v.init()" hide="v.hide()"/>
                </mx:ViewStack>