A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [AS3+JS] Flashvars with SWFObject doesnt work...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    9

    [AS3+JS] Flashvars with SWFObject doesnt work...

    Hi,
    I've tried to send some parameters to my flash app by flashvars. Unfortunently, it doesnt work. To embde flash I'm using SWFObject 2.2. I also use lib SWFAddress 2.4 (I'm stating this, because I've heard that some versions of swfobject and swfaddress are not compatible).

    Here is my html code:
    PHP Code:
    <head>
            <
    title>RacerViewer</title>
            <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <
    style type="text/css" media="screen">
            
    htmlbody background-color#ffffff;}
            
    body
            
    {
                
    margin:0;
                
    padding:0;
                
    text-align:center;
            }
            
    #flashContent
            
    {
                
    width:100%;
            }
            </
    style>
            <
    script type="text/javascript" src="swfobject.js"></script>
            <
    script type="text/javascript" src="swfaddress.js"></script>
        </
    head>
        <
    body onload="pageInit();">
            
            <
    div id="flash">
                
    Flash content goes here.
            </
    div>
            <
    script type="text/javascript">
                var 
    flashvars = {};
                
    flashvars.swfLocation "RoadRunner-war/resources/swf/";
                
                var 
    params = {};
                
    //params.id = "flashMovie";
                
    params.wmode "transparent";
                
    //params.flashvars = "swfLocation=RoadRunner-war/resources/swf/";
                
                
    var attributes = {};
                
    attributes.id "flashMovie";

                
    /*var flashvars =
                {
                    swfLocation: "RoadRunner-war/resources/swf/"
                }
                var params =
                {
                    wmode: "transparent"
                }
                
                var attributes =
                {
                    id: "flashMovie"
                };*/

                
    swfobject.embedSWF'RacerViewerPre.swf''flash''960''480'"9.0.115"falseflashvarsparamsattributes );
                
    //swfobject.embedSWF( 'RacerViewerPre.swf', 'flash', '960', '480', "9.0.115", "swfobject/expressInstal.swf", params );
            
    </script>
        </
    body
    Here is my AS code:
    Actionscript Code:
    var url:String = SWFAddress.getBaseURL().substr(SWFAddress.getBaseURL().indexOf("/")+2);
    var port:String = "";
    if( SWFAddress.getBaseURL().indexOf(":") < 0 )
        url = url.substr(0, url.indexOf("/"));
    else
    {
        port = url.substr(url.indexOf(":")+1, url.indexOf("/"));
        url = url.substr(0, url.indexOf("/"));
    }

    //loader.load( new URLRequest("RacerViewer.swf") );
    var paramObj:Object = root.loaderInfo.parameters;

    if(port != "" && port != url)
        preLoader.Komunikat.text = url+":"+port;
    else preLoader.Komunikat.text = url+" "+paramObj+" "+String(paramObj["swfLocation"])+" "+paramObj.swfLocation;

    After lanching app in webbrowser preLoader.Komunikat has text: "[Object object] undefined undefined" so there is root.loaderinfo.parameters object, but it has no paramaters in it.

    I've tried many solutions and read many tutorial or forumposts, but I havent found any that solves my problem. I'ld be grateful for any advices...

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    In the sample code I've seen, you want to wait for the "complete" event on the .swf.

    Code:
    this.loaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
    function loaderComplete(myEvent:Event) {
      trace(this.loaderInfo.parameters.swfLocation);	
    }

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    loaderInfo.parameters should be available immediately. you shouldn't need to wait for a complete event (not even sure that'd be heard).

    i'm guessing your problem is with the SWFObject syntax. try it withou SWFObject - just use satay and see if it shows up right:

    PHP Code:
    <object type="application/x-shockwave-flash" data="RacerViewerPre.swf" width="960" height="480">
        <
    param name="movie" value="RacerViewerPre.swf" />
        <
    param name="flashvars" value="swfLocation=bob" />
    </
    object
    you might also need to urlencode that value:

    PHP Code:
    encodeURIComponent("RoadRunner-war/resources/swf/"); 

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Huh, I guess you're right. You don't need to wait for the "complete" event. Though I will say the "complete" event does fire (it's the event that fires when the .swf is finished loading), and I've used the code above without problems in the past. Good to know I don't need to wait for that event though!

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    Thanks for answers, but it still doesnt work.

    Btw. what I have to do with

    PHP Code:
    encodeURIComponent("RoadRunner-war/resources/swf/"); 
    could you explain?

  6. #6
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    encodeURIComponent is intended to encode a part (component) of a uri string. it takes special characters - like slashes - that shouldn't be passed as part of a URI. used on that string, it'd output:

    PHP Code:
    RoadRunner-war%2Fresources%2Fswf%2F 
    it may or may not be needed, but might be worth a shot.

    but... when you say:

    Thanks for answers, but it still doesnt work.
    i have to think you're doing something else wrong. i'm certain that if you use the XHTML i provided, then root.loaderInfo.parameters.swfLocation will be populated...

    if you use that markup, and have a swiff that just has this in it:

    PHP Code:
    TextField(addChild(new TextField())).text root.loaderInfo.parameters.swfLocation
    i'm pretty sure you'll see whatever value you passed in the flashvars...

    try something very small (like what i've described above) to narrow down where the problem is, then move on to debugging your actual-use scenario.

  7. #7
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    No it wasnet the case, but thanks for your effort. For those who have same issue, hes an answer:

    I was using RSL's in my publish settings. All I need to do is set my linkage to Merged into code and then the code works as expected.

    File > Publish Settings... > Flash > Actionscript 3.0 Settings > Runtime Shared Library Settings > Merged into Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center