Need Example Code

Hi, I’m trying to create a dynamic URL from within my Flash MX file.

I am passing a variable “customer_ID” to the flash as a parameter field, and I’ve verified that it is being passed and received correctly.

I have a button in the flash, which, when pushed, I want to link to

http://www.somedomain.com/customer= (whatever the customer_ID is)

I’ve tried everything I’ve seen in all the tutorials, but my URL is always either an empty string, unevaluated, or only the literal part.

Can someone please show me a piece of example code to do this seemingly simple thing?

Thanks

It’s just a bit of simple string manipulation.

Something like this should work…

id = 1;
getURL('http://www.somedomain.com/?customer=’+id);

That was the first thing I tried, except I passed the ID as a parameter from my html code.

I am sure the ID variable is being passed correctly, since I can make the ID appear in a dynamic text field.

There was one other difference: I used a double quote instead of a single quote to enclose the string… I will try this and report back

Thanks!

Single or Double quotes really shouldn’t make a difference.

It is very odd that your id variable can be passed to a dynamic textbox, but it cannot be passed to your getURL string.

hm… that is very strange.
one other thing that i could suggest would be to try something like this:

[edit]try something like this, first:

id = 1;
newHREF = "http://www.somedomain.com/?customer="+id;
trace(newHREF); //just to test it...
getURL(newHREF);

[/edit]

in your webpage, put this html code between the head tags of your source:

<script language="javascript">
function redirect(id) {
  window.location.href="http://www.somedomain.com/?customer="+id;
}
</script>

and from the flash movie call:

getURL("javascript: redirect("+id+");")

i think that should be it.

Any idea why this would not work?

In my html code object definition:
[size=2]
<param name=“movie” swLiveConnect=true value=“header.swf?id=12345”>
<param name=quality value=high>
<embed src=“header.swf?id=12345” quality=high …

I can verify that the variable called “id” is passed, because a dynamic text line is set to “id” and shows it just fine.

For the OnRelease event of some button elsewhere in the Flash

on (release) {
getURL(“http://www.domain.com/page.php?id=”+id, “”, “GET”);
}

The URL that shows up and the page I am taken to is “http://www.domain.com/page.php?id=

(By the way, the “expression” button is checked for the URL in the code editor.)

I am using Flash MX under MacOSX.

Any ideas?
[/size]

Did you try removing the “GET” statement… it’s an optional argument of the getURL() command.

If you call the function form within a movie clip let’s say, and your dynamic textfield is on _root… it could appear fine in the dynamic text on the _root… but the “id” variable wouldn’t trace fine in another MC… because you should call it as _root.id.

or try this.
<param name=“flashvars” value=“id=1”>

Thank You!

Prefixing the “id” variable with “_root.” worked… which means, I suppose, that I was having a problem with the scope of the variable.

I really appreciate your efforts to help me out… I think I better break out the book on this if I don’t even know why my variable wasn’t globally accessible!

Thanks again!

was globally accessible… but globally doesn’t mean that :). I was thinking that too before I learned.
You can have 2 global variables… lets say var1 in _root. and var1 in _root.mc
both ar global. You can reffer them from anywhere you want in that scene but you must provide a path.
Local variables are in functions for example. To define a local variable you must preced it with “var”. var var1;
I just learned it myself a couple of days ago :smiley: