# Playing my embedded .swf using javascript of html?

**URL:** <https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058>\
**Category:** Uncategorized\
**Created:** [June 22, 2008, 7:59pm UTC](https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058 "2008-06-22T19:59:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gibry21](https://avatars.discourse-cdn.com/v4/letter/g/3bc359/32.png) [@gibry21](https://forum.kirupa.com/u/gibry21)\
**Post date:** [June 22, 2008, 7:59pm UTC](https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058/1 "2008-06-22T19:59:44Z")

</div>

Hi folks,

Hi currently have an embedded .swf on an html page, the swf code is on a single frame and is all controlled using AS3, the script runs as soon as the swf is played.

What I am trying to acheive should be simple but I cant figure it out with my limited knowledgs of javascript.

If I put a stop(); at the start of my swf.

Can I set some kind of roll over state using html or javascript, so that when a user rolls over the swf movie on the html page…the swf will play?

Understand?

Thanks.

---

<div class="post-metadata">

**Author:** ![Alex\_Lexcuk](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Alex\_Lexcuk](https://forum.kirupa.com/u/Alex_Lexcuk)\
**Post date:** [June 23, 2008, 12:59pm UTC](https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058/2 "2008-06-23T12:59:42Z")

</div>

you only send  
var javascript to Actionscript (revers AS3.0 javascript) mast create special function in AS3.0 and javascript  
example

```auto

//firstframe code
var newText = ExternalInterface.addCallback("text_for_swf", /*null,*/ func_external_text);
function func_external_text(newVal) 
{
stop();//stop play
}

```

html code

```auto

<html>
<head>
	<title>SEND MESSAGE FROM IAVASCRIPT TO SWF</title>
	<meta name="description" lang="ru" content="FlashVars">
	<meta name="keywords" lang="ru" content="FlashVars">
	
     <link rel="stylesheet" type="text/css"
      href="http://dnadillo.dn.ua/fla/style.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
	<script type="text/javascript" src="swfobject.js"></script>

</head>
<div style="position:absolute;top:0;left:0; filter:alpha(opacity=100); background:0;"> 

<div id="myAlternativeContent">
</div>

<! __________start______________________ swf>
</div>
<div id="my_flash_view">
</div><br>
<! ____________end__________________________ swf _________________ >

<!button model>
<button id="my_button" onclick="but_1_click()"> Bigger</button>
<!end button model>

SCRIPT DO IT
<script language="JavaScript">
<!--
var where = document.referrer+"#f_e";

document.all.myAlternativeContent.innerHTML="<a href="+where+">&#1053;&#1072;&#1079;&#1072;&#1076;</a>";

     var flashvars_1 = {str_1:"hello",str_2:"Hi anyone"};
     var params_1 = {};
     var attributes_1 = {};
     params_1.play = "true";
     params_1.menu = "false";
// params_1.scale = "noscale";
// params_1.wmode = "transparent";//error gen with Opera and FF (IE7 works mega good)
// params_1.bgcolor = "#003438";

    swfobject.embedSWF("js-swf-external-interface.swf", "my_flash_view", "50%", "50%", "9.0.0", false, flashvars_1, params_1, attributes_1);

var i=1;
//button code
function but_1_click()
{
   i++;
   my_flash_view.text_for_swf(""+i);///////////send message swf
}

//-->
</script>

</html>

```

[http://dnadillo.dn.ua/fla/js-swf-html/js-swf-html-external.html](http://dnadillo.dn.ua/fla/js-swf-html/js-swf-html-external.html)  
[http://dnadillo.dn.ua/fla/js-swf-html/js-swf-html.zip](http://dnadillo.dn.ua/fla/js-swf-html/js-swf-html.zip)  
[http://www.swffix.org/swfobject/testsuite/swfobject.js](http://www.swffix.org/swfobject/testsuite/swfobject.js)  
[http://www.swffix.org/swfobject/generator](http://www.swffix.org/swfobject/generator)

---

<div class="post-metadata">

**Author:** ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)\
**Post date:** [June 23, 2008, 3:26pm UTC](https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058/3 "2008-06-23T15:26:24Z")

</div>

Depending on how dependent your site’s layout is on the flash element, you could write your flash movie to a div when the user clicks on a button/image/link, etc. If it’s not written to the page until they push the button, it won’t be playing. Just a thought. If you are interested in this idea post back and I will tell you how to do it.

---

<div class="post-metadata">

**Author:** ![gibry21](https://avatars.discourse-cdn.com/v4/letter/g/3bc359/32.png) [@gibry21](https://forum.kirupa.com/u/gibry21)\
**Post date:** [June 23, 2008, 3:56pm UTC](https://forum.kirupa.com/t/playing-my-embedded-swf-using-javascript-of-html/264058/4 "2008-06-23T15:56:22Z")

</div>

Thanks for both your replies, the first reply looks slightly complicated based on my already complicated script but potentially could be exactly what I’m looking for.  
But I dont want the user to have to click anything just mouseouver.

The second reply, actionaction, I want my movie to be on the page as soon as the user enters it, but dont want it to play untill they enter the swf, I guess I could cheat and create an image on my first frame that looks exactly like the first frame of my movieclip, then create a mouse over that loads the movie clip? but not sure if this would interfere as the speed and movement of my swf is controlled by the distance the user is away from the centre of my swf…similar to that of many scrolling galleries…

this is the page that might explian it better, currently when u access the page you will see the cube is spinning and moving quite rapidly depending on your pointer position…I want it to be static untill the user moves over it, or at least gets closer to it…perhaps a mask??

The more help the better, i’m stretchin my knowledge with this one as it is. I can send the AS3 to if required.

[http://www.gibsonmedia.co.uk](http://www.gibsonmedia.co.uk)

thanks guys.
