4 Replies Latest reply on Oct 12, 2011 2:12 AM by Umesh Gamit

    display/load and Unload SWF in flex

    Umesh Gamit

      hi friends

       

      i wnat to disply external SWF file into flex but without using SWFLOader(it's make lot's of problem) nad i also Embed that SWF

       

      this is code

       

      [Embed(source="1.swf")]

      private var loadswf:Class;

       

      private function load():void{

      var symb:MovieClip = new loadswf() as MovieClip;

      this.addChild(symb);

      }

       

      it's give me error....

      TypeError: Error #1034: Type Coercion failed: cannot convert demos_loadswf@39ab3c1 to mx.core.IUIComponent.

       

      please help to resolve this error or give me suggestion to simple Disply/Load and Unload Embed SWF file in flex

        • 1. Re: display/load and Unload SWF in flex
          Flex harUI Adobe Employee

          Add it to a UIComponent

          • 2. Re: display/load and Unload SWF in flex
            Umesh Gamit Level 1

            thnx Flex harUI

             

            i added UI componentes now my full code is like..

             

                    import mx.controls.Image;    

                    import mx.controls.Alert;

                    [Embed(source = "1.swf")]

                    public var SWF:Class;

                    [Embed(source = "2.swf")]

                    public var SWF2:Class;

                   

                    private var mc:MovieClip;

                    private var img:Image;

                   

                    protected function checkBtn_clickHandler(event:MouseEvent):void

                    {

                        clear();

                        img = new Image();

                        img.width=Number("700");

                        img.height=Number("700");

                        mc = new MovieClip();

                        mc = MovieClip(new SWF());

                        img.source = mc;

                        vBox0.addChild(img);

                    }

                    protected function critcalBtn_clickHandler(event:MouseEvent):void

                    {

                        clear();

                        img = new Image();

                        img.width=Number("700");

                        img.height=Number("700");

                        mc = new MovieClip();

                        mc = MovieClip(new SWF2());

                        img.source = mc;

                        vBox0.addChild(img);

                    }

                    protected function clear():void

                    {

                        try{

                            if(mc!=null){

                                flash.media.SoundMixer.stopAll();

                                img.source="";

                                img.source=null;

                                mc=null;

                                vBox0.removeChild(DisplayObject(img));

                                vBox0.removeAllElements();

                                vBox0.removeAllChildren();

                            }

                        }catch(e:Error){

                            Alert.show(e + " ----::---- ");

                        }

                    }

             

             

            <mx:Canvas id="vBox0" width="700" height="700" ></mx:Canvas>

            <mx:HBox >

                    <mx:Button id="checkBtn" label="first" click="checkBtn_clickHandler(event)"/>

                    <mx:Button id="critcalBtn" label="second" click="critcalBtn_clickHandler(event)"/>

            </mx:HBox>

             

             

            now my error gone!!! but one problem is there when i unload my first SWF and load second SWF(on button click), my first SWF sound are still play in Background, i cn't unstand Y this will happen coz i already remove all object and child from my Canvas.

             

            any help on this....

            • 3. Re: display/load and Unload SWF in flex
              Flex harUI Adobe Employee

              You probably need to call unloadAndStop() on the Loader

              • 4. Re: display/load and Unload SWF in flex
                Umesh Gamit Level 1

                thx Flex harUI for your replay

                 

                i just reslove my issue(sound play )

                 

                import mx.controls.Image;

                        import mx.events.*

                        [Embed(source = "1.swf")]

                        public var SWF:Class;

                        [Embed(source = "2.swf")]

                        public var SWF2:Class;

                        private var mc:MovieClip;

                        private var img:Image;

                        protected function checkBtn_clickHandler(event:MouseEvent):void

                        {

                            clear();

                            img = new Image();

                            img.width=Number("700");

                            img.height=Number("700");

                            mc = new MovieClip();

                            mc = MovieClip(new SWF());

                            img.source = mc;

                            vBox0.addChild(img);

                        }

                       

                  

                        protected function critcalBtn_clickHandler(event:MouseEvent):void

                        {

                            clear();

                            img = new Image();

                            img.width=Number("700");

                            img.height=Number("700");

                            mc = new MovieClip();

                            mc = MovieClip(new SWF2());

                            img.source = mc;

                            vBox0.addChild(img);

                        }

                        private function unloadSWF(event:Event):void {

                                flash.media.SoundMixer.stopAll();

                        }

                        protected function clear():void

                        {

                            try{

                                if(mc!=null){

                                    mc.addEventListener(Event.REMOVED,unloadSWF);

                                    img.source="";

                                    img.source=null;

                                    mc=null;

                                    vBox0.removeChild(DisplayObject(img));

                                    vBox0.removeAllElements();

                                    vBox0.removeAllChildren();

                                }

                            }catch(e:Error){

                                Alert.show(e + " ----::---- ");

                            }

                        }

                 

                <mx:Canvas id="vBox0" width="700" height="700" ></mx:Canvas>

                <mx:HBox>

                    <mx:Button id="checkBtn" label="first" click="checkBtn_clickHandler(event)"/>

                    <mx:Button id="critcalBtn" label="second" click="critcalBtn_clickHandler(event)"/>

                </mx:HBox>