AS3 Pass FlashVars to loaded swf

前端 未结 4 1555
名媛妹妹
名媛妹妹 2020-12-06 02:57

I have a A.swf which loads B.swf onto a movieclip and needs to pass it some FlashVars. When loading B.swf with html, I can pass FlashVars fine. When passing from A.swf, it g

4条回答
  •  误落风尘
    2020-12-06 03:23

    It's not necessary that "A" pass FlashVars to "B". Just have B access the FlashVars itself. The following will work whether B is inside of A, or top-level itself:

    Add an ADDED_TO_STAGE event listener in B's constructor. e.g.:

    function B(){
        this.addEventListener(Event.AddedToStage, onAddedToStageHandler);
    }
    

    When you have access to the stage you can now access the FlashVars in A this way:

    To properly see a variable called myVar flashVar in B.swf, you do (inside B):

    private function onAddedToStageHandler(){
    var flashVars : Object = LoaderInfo(this.stage.loaderInfo).parameters;
    // now you have access to your flashVars!
    trace(flashVars.myVar);
    }
    

    stage.loaderInfo is what you need to look at.

提交回复
热议问题