开发者

reading flashvars problem for swfobject

开发者 https://www.devze.com 2023-04-08 15:01 出处:网络
I have a flash swf of 1.2mb. am embeding it with swfobject u开发者_如何学Pythonsing dynamic embeding .

I have a flash swf of 1.2mb. am embeding it with swfobject u开发者_如何学Pythonsing dynamic embeding .

<script type="text/javascript">
var flashvars = {};

flashvars.campaignid = "12345678890";
var params = {};
params.allowscriptaccess = "always";
var attributes = {};
swfobject.embedSWF("soccer.swf", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes);
</script>

am tring to read campaignid inside my document class ...

the code is like

public function Main()
{    
    loaderInfo.addEventListener(ProgressEvent.PROGRESS,update); 
    loaderInfo.addEventListener(Event.COMPLETE,onLoadedMovie); 
}                 
private function update(e:ProgressEvent):void         
{
}

private function onLoadedMovie(e:Event)
{
    campId=this.root.loaderInfo.parameters["campaignid"]; 
}

when i alert the value i got null when i use the same method in a small file it works.. can anyone help me? regards


I got the answer by adding variable in the embed code. like this

swfobject.embedSWF("soccer.swf?campaignid=1234556"", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes);

Thanks for the help :)


Adam Harte's answer is correct, I think the problem lies somewhere within your AS3 code, the following especially confused me:

public function Main() 
{     
    loaderInfo.addEventListener(ProgressEvent.PROGRESS,update);  
    loaderInfo.addEventListener(Event.COMPLETE,onLoadedMovie);  
}

private function update(e:ProgressEvent):void { } 

private function onLoadedMovie(e:Event) 
{ 
    campId=this.root.loaderInfo.parameters["campaignid"];  
} 

I've created a simple(and working) example of how your code should look:

index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>FlashVars</title>
    <meta name="language" content="en" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <script src="js/swfobject.js" type="text/javascript"></script>
    <script type="text/javascript">
        var flashvars = { campaignid: "12345678890" };
        var params = { menu: "false", scale: "noScale", allowFullscreen: "true", allowScriptAccess: "always", bgcolor: "", wmode: "direct" };
        var attributes = { id:"FlashVars" };
        swfobject.embedSWF("FlashVars.swf", "altContent", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
    </script>
    <style type="text/css">
        html, body { height:100%; overflow:hidden; }
        body { margin:0; }
    </style>
</head>
<body>
    <div id="altContent">
        <h1>FlashVars</h1>
        <p>Alternative content</p>
        <p>
            <a href="http://www.adobe.com/go/getflashplayer">
                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
        </p>
    </div>
</body>
</html>

Main.as(document class):

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class Main extends Sprite 
    {
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }// end function

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            if (loaderInfo.parameters.campaignid)
            {
                var textField:TextField = new TextField();
                textField.autoSize = TextFieldAutoSize.LEFT;
                textField.text = loaderInfo.parameters.campaignid;
                addChild(textField);

            }// end if

        }// end function

    }// end class

}// end package

The following is an image of the example beening run in a browser:

reading flashvars problem for swfobject


Maybe try getting the var after your Main class has been added to the stage. This will make sure everything is loaded and ready. Try something like this:

public function Main()
{
    if (stage) init();
    else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void 
{
    removeEventListener(Event.ADDED_TO_STAGE, init);

    var campId:String = this.root.loaderInfo.parameters["campaignid"];
    trace('campId', campId);
}
0

精彩评论

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

关注公众号