开发者

Sending variable from fla to document class and then accessing it

开发者 https://www.devze.com 2023-03-09 16:20 出处:网络
I want to find out whether my swf was loaded locally or from another swf. For this purpose I have declared a variable \'parentType\' in my fla.

I want to find out whether my swf was loaded locally or from another swf. For this purpose I have declared a variable 'parentType' in my fla. var parentType:String = String(parent); There is a function in the document class that determines whether swf was loaded locally or from another swf. The name of the function in the document class is 'externalOrInternal'. The varaible parentType is passed as a parameter to the function externalOrInternal . externalOrInternal(parentType); The name of the document class is Main. In the constructor of Main I have the function pollResize() (the use of this function is to listen for the resizing event. That part of the code is not shown in the snippet given below).

My fla is as follows.

var pare开发者_JAVA百科ntType:String = String(parent);
externalOrInternal(parentType);

My document clas is as follows.

package {

    import flash.display.MovieClip;


    public class Main extends MovieClip {

        private var swfParentType:String;

        public function Main1() {

            pollResize();
        }

        public function externalOrInternal(parentType:String) {



            swfParentType=parentType;

            trace("Inside externalOrInternal");
            trace(swfParentType);


        }

        private function pollResize():void {

            trace("Inside pollResize");
            trace(swfParentType);


        }
    }
}

When I run this is what gets traced out

Inside pollResize

null

Inside externalOrInternal

[object Stage]

I see that swfParentType is has value insde the function externalOrInternal. My doubt is why null is traced inside the function pollResize. Why is it not [object Stage] as inside externalOrInternal. Due to this I am not able proceed further with the stage resizing event.What needs to be done so that proper value is traced in the function pollResize.


According to your trace, pollResize is called before externalOrInternal, where you set swfParentType, so it is normal it traces null at first. Also, your constructor is badly called, it reads Main1 when it should be Main, although that won't solve your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消