A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Parsing Query string in js to pass to swf

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    31

    Parsing Query string in js to pass to swf

    I'm trying to pass a variable into an swf using query strings. Am loading the swf through swfobject.js in my aspx page.

    Code:
    <div id="flashcontent">Replacement copy</div>
    
    
    <script type="text/javascript">
    var myVar = new SWFObject("mymovie.swf", "name", "740", "540", "8", "#ffffff");
    so.addVariable("varInFlash", "<%=Request.QueryString["variableName"]%>");
    myVar.write("flashcontent");
    </script>
    with a

    Code:
    _root.varInFlash;
    in the first frame of my movie.


    Only problem is, that with the so.addVariable statement in there, the swf doesn't load. I comment out that line, and it loads just fine.

    So I have syntax off somehow? I think for asp that the brackets [ ] are needed, but not sure.

    Or is my javascript syntax off??

    Anyone here have some input?

    THANKS!

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    What version of SWFObject are you using?

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    31

    swfobject

    had gone to googlecode to get latest, but let me double check...

  4. #4
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    If you're using the latest, 2.x series, you're using the completely wrong syntax. Syntax has changed from 1.5 to 2.0. Revise your code, and then we'll take a better look at it.

  5. #5
    Member
    Join Date
    Mar 2009
    Posts
    31
    Ah! Had 1.5 but then that wasn't working, so grabbed a temp copy of 2.2.

    That would explain a lot!

  6. #6
    Member
    Join Date
    Mar 2009
    Posts
    31
    Okay, got it working with 2.2 and

    Code:
    <param name="flashvars" value=<%=Request.QueryString%> />
    simple.

    Don't know why original request was failing with 1.5, but guess it doesn't matter as have moved on to 2.2.

    Thanks for help!!

  7. #7
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Wait, why are you using a <param> tag with 2.2? Your code should be similar to:

    swfobject.embedSWF(....);

  8. #8
    Member
    Join Date
    Mar 2009
    Posts
    31
    Ha!
    You are absolutely right, and that is how I started writing it.

    Then I noticed the "SWFObject 2 HTML and JavaScript generator v1.2" and tried to figure out why that was being distributed if it produced different code.

    So I ran with it.


    I got it to work (which is more than I can say with what I thought was supposed to work with 1.5), so now I'm backing out to the swfobject.embedSWF(....); code.

  9. #9
    Member
    Join Date
    Mar 2009
    Posts
    31
    So basically,

    Code:
    	<script type="text/javascript" src="swfobject.js"></script>
    	<script type="text/javascript">
    	swfobject.embedSWF("movie.swf", "swfWin", "400", "300", "8.0.0", flashvars, params, attributes);
    	</script>
    	</head>
    	<body>
    		<div id="swfWin">
                             SWF goes here 
    		</div>
    	</body>
    is the proper way to do it, and I just have to pass the query to flashvar.

  10. #10
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    flashvars, params, and attributes are objects that you need to define.

    To short hand it, you can just use {} to fill the gap if there's nothing needed.

    In your case, you could do this:
    Code:
    	<script type="text/javascript" src="swfobject.js"></script>
    	<script type="text/javascript">
    	swfobject.embedSWF("movie.swf", "swfWin", "400", "300", "8.0.0", "expressInstall.swf", {varInFlash: "<%=Request.QueryString["variableName"]%>"}, {}, {});
    	</script>
    	</head>
    	<body>
    		<div id="swfWin">
                             SWF goes here 
    		</div>
    	</body>

  11. #11
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Ha, and I just now looked at your original attempt again. I see what was wrong. You had your variable names mixed up. You started out defining a myVar, then when you call the addVariable, you used so. If you changed it to
    Code:
    myVar.addVariable("varInFlash", "<%=Request.QueryString["variableName"]%>");
    it should work.

  12. #12
    Junior Member
    Join Date
    Aug 2009
    Posts
    1

    Angry Working with Flashvars

    I have tried n no of ways to access flash vars in as3.
    Anyone here have some input?

    THANKS!
    That would explain a lot!

  13. #13
    Member
    Join Date
    Mar 2009
    Posts
    31
    Quote Originally Posted by MyFriendIsATaco View Post
    Ha, and I just now looked at your original attempt again. I see what was wrong. You had your variable names mixed up.
    Duh! I was so focused on "maybe I have a delimter wrong" or thinking that the syntax wasn't right, that I didn't even notice that.

    But then again no one noticed that until you just did...


    But with that correction, it is producing an "identifier expected" error within the request.

    Code:
                             __w.Write(Request.QueryString["variableName"])
                                                           ~
    I thought the Request.QueryString was properly formed?

  14. #14
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    I know nothing about ASP or .NET. I'm purely a PHP/Python guy. Anti-Microsoft.

    @prj To access FlashVars in AS3, do:
    Code:
    root.loaderInfo.parameters.myFlashVar

  15. #15
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Hmm, accord to this page: http://www.w3schools.com/ASP/coll_querystring.asp

    You syntax should be: Request.QueryString("variableName")

    Parenthesis vs square brackets.

  16. #16
    Member
    Join Date
    Mar 2009
    Posts
    31
    Quote Originally Posted by MyFriendIsATaco View Post
    Hmm, accord to this page: http://www.w3schools.com/ASP/coll_querystring.asp

    You syntax should be: Request.QueryString("variableName")

    Parenthesis vs square brackets.
    Yeah, not an asp guy myself. Just helping out on this. Good learning situation.

    And I read somewhere that the square brackets have to be used on asp. What I was doing wasn't working, so I changed them to square brackets and stopped getting an error. Of course, now that I'm getting into it, I'm finding a lot of things I read about in researching this have just been plain wrong.

Tags for this Thread

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