Hi,
I know when passing vars to an AS3 movie you can use the query string like
mymovie.swf?Var1=something&Var2=something_else
but what about passing them via the URL?
I know that YouTube does this, there embed SWFs are
http://www.youtube.com/v/v3xYkyw86QM
with the red bit being the video URL. The server is Apache so it isn't something to do with FMS or any other Flash server
and it can't be done with rewrites like you normaly would because its client side
How can I do this with my flash movies?
Thanx,
Sam Rudge

Dani AI

Generated

asked how to get a URL path segment into an AS3 SWF (the YouTube-style path case). is on the right track — this must be done in the page (client-side) and then handed to Flash. Two reliable patterns:

  1. Pass the value at embed time (flashvars):
  • Extract the piece you need from window.location in JavaScript.
  • Build a flashvars string and supply it when you embed the SWF (or set the <param name="flashvars">).
  • In AS3 read the value from loaderInfo.parameters.

Example (conceptual):

var parts = window.location.pathname.split('/').filter(Boolean);
var id = parts[parts.length - 1];
var flashvars = 'id=' + encodeURIComponent(id);
// embed the SWF with that flashvars string
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var id:String = params.id;
  1. Or pass it at runtime (ExternalInterface):
  • Let the SWF expose a callable AS3 function with ExternalInterface.addCallback.
  • From the page, after parsing the URL, call that function on the embedded object.

Example (conceptual):

var swf = document.getElementById('mySwfId');
swf.setId(extractedId);
ExternalInterface.addCallback('setId', function(value:String):void {
  // handle value
});

Troubleshooting and cautions:

  • Ensure the embed has a stable id and use a cross-browser embed helper (swfobject) if needed.
  • allowScriptAccess must permit scripting (default is usually fine for same-domain).
  • If the SWF/page live in different origins or inside cross-origin iframes, browser same-origin rules can block access.
  • Always validate/sanitize any ID you get from the URL before using it.

See Adobe’s ExternalInterface docs for exact AS3 API details and the browser Location API docs for parsing the URL:
ExternalInterface (ActionScript 3 reference)
Location API (MDN)

Member Avatar for Member #334542

Utilize the javascript to extract the path from the url and pass it to the flash and get the value from "external interface"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.