A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 pass URL parameter

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929

    AS3 pass URL parameter

    I must be missing something obvious. I'm trying to pass a parameter from a URL into a text field in flash, but it doesn't seem to work...

    I've got a dynamic text field (display as html is checked), with an instance name txt_txt. Here's the only line of code in the file:

    Code:
    txt_txt.htmlText="test   "+this.loaderInfo.parameters.nameVar;
    And, when I upload it and use the following, I get "test undefined" as my return!?

    http://www.brianwpiper.com/fk/tstURL...ameVar=testing

    Can anyone help out on this??? What obvious thing am I overlooking??

    TIA!!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The parameters available from loaderInfo are the flashvars (if any) set in the embed/object for the swf. URL parameters for the page are not automatically available. To get them in the flashvars, you'll need to set the flashvars parameter with or whatever javascript you're using to generate the embed/object tag. If you're using a server side script to generate the page, you could put the parameters on the swf url there instead.

  3. #3
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Hmm....thanks...so, there's no way to directly get the info from the URL parameters??

    The flash file is being launched in a modal window put together by the client so I'll have to work with them to make sure the parameters get read and passed to the flashvars correctly and the right javascript is in there...

    Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Not directly, no. But if you can have script access, you could use ExternalInterface to run some javascript to get the page url, then parse it yourself.

    Something like this:
    Code:
    function getPageParams():Object{
      var params:Object = {};
      if (ExternalInterface.available){
        var pageurl:String = ExternalInterface.call("function getPageURL(){return document.location.href}");
        var paramStr:String = pageurl.substr(pageurl.indexof("?")); //get the part after ?
        var paramPairs:Array = paramStr.split('&'); //split into name/value pairs
        for (var i:int = 0; i < paramPairs.length; i++){
          var nameVal:Array = paramPairs[i].split("=");
          params[nameVal[0]] = nameVal[1];
        }
      }
      return params;
    }

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