# Struggle with some basic Java Script

**URL:** <https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622>\
**Category:** web dev\
**Created:** [May 17, 2008, 6:33pm UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622 "2008-05-17T18:33:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevorsaint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trevorsaint/32/268_2.png) [@trevorsaint](https://forum.kirupa.com/u/trevorsaint)\
**Post date:** [May 17, 2008, 6:33pm UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622/1 "2008-05-17T18:33:32Z")

</div>

I am simply trying to pass a value to flash and really struggling to get it working.

Here is my setup.

**JAVASCRIPT FUNCTION**

[COLOR=“DarkRed”]\<script type=“text/javascript”\>  
function passImage(url) {  
window.document.movie.SetVariable(“image”, url);  
window.alert(url)  
}  
\</script\>[/COLOR]

**FLASH FILE OUTPUTTED USING SWF OBJECT**

[COLOR=“DarkRed”]\<script type=“text/javascript”\>

var so = new SWFObject(“swf/image.swf”, “movie”, “300”, “300”, “6”, “#ffffff”);  
so.addParam(“swLiveConnect”, “true”);  
so.addParam(“allowScriptAccess”, “sameDomain”);  
so.addParam(“quality”, “high”);  
so.addParam(“scale”, “noscale”);  
so.addParam(“loop”, “false”);  
so.addParam(“wmode”, “transparent”);  
so.addVariable(“image”, “01.jpg”)  
so.write(“flash”);

\</script\>[/COLOR]

**HTML TO LAUNCH JAVASCRIPT FUNCTION**

[COLOR=“DarkRed”]\<dl id=“dlQuickLinks”\>  
\<dt\>FEATURED IMAGES:\</dt\>  
\<dd\>\<a href="#" onclick=“passImage(‘01.jpg’); return false;”\>Image One\</a\>\</dd\>  
\<dd\>\<a href="#" onclick=“passImage(‘02.jpg’); return false;”\>Image Two\</a\>\</dd\>  
\<dd\>\<a href="#" onclick=“passImage(‘03.jpg’); return false;”\>Image Three\</a\>\</dd\>  
\</dl\>[/COLOR]

All seems fine to me but for some reason the file is not being changed on the fly as it should. Can anyone spot the mistake I am doing here?

What is suppose to happen is that when you click Image One then the variable via flash will change and the image will change accordingly. I can do it using a querystring i.e [COLOR=“DarkRed”]index.asp?image=04.jpg[/COLOR] but not using javascript.

**WHY DO I WANT TO USE JAVASCRIPT?**

Prevents a page refresh.

I would really appreciate any links, advice or help as I am burnt out with searching the web and attempting to find my error alone. Any guidance greatly appreciated.

Many thanks

Trevor

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 18, 2008, 5:15am UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622/2 "2008-05-18T05:15:02Z")

</div>

Don’t think this is possible… Why don’t you just remove the flash thing all together? Just have \<img\> and you can easily change the imc src on the fly without page refresh…

---

<div class="post-metadata">

**Author:** ![trevorsaint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trevorsaint/32/268_2.png) [@trevorsaint](https://forum.kirupa.com/u/trevorsaint)\
**Post date:** [May 18, 2008, 9:10am UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622/3 "2008-05-18T09:10:58Z")

</div>

Thanks for your reply.

This is basically to load different flv files into flash using javascript.

The demonstration below is just a quick demonstration. I am 99% sure it is possible as they do it on the CNN website but I cannot for the life of me figure it all out.

> **[Video News - CNN](https://edition.cnn.com/videos)**
>
> Watch breaking news videos, viral videos and original video clips on CNN.com.

Anyone else help me out?

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 18, 2008, 4:44pm UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622/4 "2008-05-18T16:44:09Z")

</div>

Sorry I can’t help more. I don’t know about flash. ☹

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [May 20, 2008, 1:41pm UTC](https://forum.kirupa.com/t/struggle-with-some-basic-java-script/260622/5 "2008-05-20T13:41:20Z")

</div>

I’d throw an interval into flash that checks a certain variable in the address bar. If it is the same as the temp variable, leave it the way it is. Yet, if the variable has changed, take that variable value down instead. I’d assume it would have to be a variable in your params that would need to be changed. There must be a way to change the query string without refreshing the page.

Just throwing that out there.
