# Need Example Code

**URL:** <https://forum.kirupa.com/t/need-example-code/65414>\
**Category:** flash\
**Created:** [September 26, 2004, 4:29am UTC](https://forum.kirupa.com/t/need-example-code/65414 "2004-09-26T04:29:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteFeather](https://avatars.discourse-cdn.com/v4/letter/w/e79b87/32.png) [@WhiteFeather](https://forum.kirupa.com/u/WhiteFeather)\
**Post date:** [September 26, 2004, 4:29am UTC](https://forum.kirupa.com/t/need-example-code/65414/1 "2004-09-26T04:29:19Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 26, 2004, 4:51am UTC](https://forum.kirupa.com/t/need-example-code/65414/2 "2004-09-26T04:51:15Z")

</div>

It’s just a bit of simple string manipulation.

Something like this should work…

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 26, 2004, 6:27pm UTC](https://forum.kirupa.com/t/need-example-code/65414/3 "2004-09-26T18:27:48Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 26, 2004, 7:28pm UTC](https://forum.kirupa.com/t/need-example-code/65414/4 "2004-09-26T19:28:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 26, 2004, 9:01pm UTC](https://forum.kirupa.com/t/need-example-code/65414/5 "2004-09-26T21:01:51Z")

</div>

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:

```auto
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:

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

```

and from the flash movie call:

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

```

i think that should be it.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 4:07am UTC](https://forum.kirupa.com/t/need-example-code/65414/6 "2004-09-27T04:07:59Z")

</div>

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=](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=](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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 7:06pm UTC](https://forum.kirupa.com/t/need-example-code/65414/7 "2004-09-27T19:06:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 7:24pm UTC](https://forum.kirupa.com/t/need-example-code/65414/8 "2004-09-27T19:24:58Z")

</div>

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”\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 8:23pm UTC](https://forum.kirupa.com/t/need-example-code/65414/9 "2004-09-27T20:23:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 28, 2004, 8:13am UTC](https://forum.kirupa.com/t/need-example-code/65414/10 "2004-09-28T08:13:50Z")

</div>

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 😃
