2 Replies Latest reply on Oct 25, 2011 5:40 AM by agus6287

    SWF LOADER null pointer exception

    agus6287

      Hello,

      I an trying to load and stop a SWF video.

       

      The video loads perfectly but when I click on stop, it gives me a null pointer exception.

      The thing is this, in STOP, the variable asociation:

                      var mc : MovieClip = loader.content as MovieClip;

      gives me as a result null (mc:null) , so when I excecute  mc.stop(); it gives me a null pointer exception.

      Why is mc null? if the content exists and loads?

       

      thank you VERY MUCH!

      Agustina

       

       

      CODE

      *********************************

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="1280" height="720" xmlns:views="code.views.*" xmlns:controllers="code.controllers.*" backgroundColor="#000000" creationComplete="OnCreationComplete()">

                <mx:Script>

                <![CDATA[

                          import mx.core.UIComponent;

                          private var loader:Loader;

       

       

                          private function OnCreationComplete():void

                          {

                                    var url : String ="flashvideos/Advertising.swf";

                                    loader = new Loader();

                                    var request:URLRequest = new URLRequest(url);

                                    loader.load(request);

                                    loaderHolder.rawChildren.addChild(loader as DisplayObject);

                          }

       

       

                          private function onStop():void

                          {

                               var mc : MovieClip = loader.content as MovieClip;

                               mc.stop();

                          }

       

       

                          private function onPlay():void

                          {

                               var mc : MovieClip = loader.content as MovieClip;

                               mc.play();

                          }

      ]]>

                </mx:Script>

       

      <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">

                          <mx:Canvas id="loaderHolder" width="500" height="500"/>

                               <mx:Button label="Stop" click="onStop()"/>

                               <mx:Button label="Play" click="onPlay()"/>

      </mx:VBox>

       

      </mx:Canvas>