2 Replies Latest reply on Jun 1, 2009 10:05 AM by Michael Hovey

    this.stage in a SWF loaded into Flex

    Michael Hovey

      I'm running into an issue where I have a SWF created in Flash that adjusts its size according to parameters using Stage.scaleMode = StageScaleMode.NO_SCALE and Stage.align = StageAlign.TOP_LEFT, but for some reason the reference to this.stage is lost when its loaded into Flex. In Flex, I receive an error for Cannot access property or method of a null object reference. Is there some conflict with this.stage inside of Flex?

       

      Thanks,

      Michael

        • 1. Re: this.stage in a SWF loaded into Flex
          BennyBeta Level 4

          Make sure you are accessing this.stage property late enough during the initialization of your application.


          For instance, if you've got an application event trigger a call to an init() function, make sure the trigger is applicationComplete and not creationComplete.

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
             applicationComplete="init()">

           

          In order to access an application's stage property, to add an event listener for instance, you'll need to make use of the applicationComplete event. This event is triggered a little later in the application initialization process.

           

          Let me know if that does/not help.

           

          Ben Edwards

          • 2. Re: this.stage in a SWF loaded into Flex
            Michael Hovey Level 1

            Thanks Ben. That was pretty much the issue. Because I need to access this information inside a Flash swf, I used this instead:

            this.root.loaderInfo.addEventListener(Event.COMPLETE, init);
            

             

            Then, I was running into an issue because the Flash swf was using the dimensions of the full Flex application rather than the SWFLoader object itself. Is there a way to make the Flash piece target the SWFLoader as its "stage"?