<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marius van Witzenburg &#187; AS3</title>
	<atom:link href="http://kitara.nl/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://kitara.nl</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Sun, 20 May 2012 15:39:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to control a Flash movie from Javascript and use Javascript from Flash movies</title>
		<link>http://kitara.nl/2011/06/14/how-to-control-a-flash-movie-from-javascript-and-use-javascript-from-flash-movies/</link>
		<comments>http://kitara.nl/2011/06/14/how-to-control-a-flash-movie-from-javascript-and-use-javascript-from-flash-movies/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 21:24:10 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=352</guid>
		<description><![CDATA[Personally I dislike the usage of Flash in my websites but our clients request a lot that they want animations. Now it happens that they want the animation to act upon an action to a non-flash object. This can be difficult if you have no idea how to do that. If you read below, you [...]]]></description>
			<content:encoded><![CDATA[<p>Personally I dislike the usage of Flash in my websites but our clients request a lot that they want animations. Now it happens that they want the animation to act upon an action to a non-flash object. This can be difficult if you have no idea how to do that. If you read below, you should have no problem with getting this job done <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Control your Flash Movie from Javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Play movie</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Stop movie</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">StopPlay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Rewind movie to beginning</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Rewind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Goto next frame of MovieClip</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">TGetProperty</span><span style="color: #009900;">&#40;</span>nameOfTargetMovieClip<span style="color: #339933;">,</span> propertyIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Goto next frame of TimeLine</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GotoFrame</span><span style="color: #009900;">&#40;</span>frameNum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Zoom in or out the flash movie</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Zoom</span><span style="color: #009900;">&#40;</span>relative percentage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set variable and make it available via ActionScript</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SetVariable</span><span style="color: #009900;">&#40;</span>variableName<span style="color: #339933;">,</span> variableValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Get variable for usage in JavaScript</span>
<span style="color: #003366; font-weight: bold;">var</span> myVariable <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myFlashMovie'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GetVariable</span><span style="color: #009900;">&#40;</span>variableName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To control Javascript functions you can call it like this:</p>
<p><strong>ActionScript 1/2</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">getURL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;javascript:name_of_your_function();&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><strong>ActionScript 3 direct call</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;javascript:name_of_your_function();&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">try</span> <span style="color: #66cc66;">&#123;</span>
  navigateToURL<span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error occurred!&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>ActionScript 3 event mouse click call</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">movieClipName.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, callLink<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> callLink:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;javascript:name_of_your_function();&quot;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0066CC;">try</span> <span style="color: #66cc66;">&#123;</span>
    navigateToURL<span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error occurred!&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>For some more information about these methods, please check out the <a href="http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html" class="broken_link">Adobe</a> website.</p>
<p>I hope this helps you out with getting that Flash Movie behave like you want it to <img src='http://kitara.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2011/06/14/how-to-control-a-flash-movie-from-javascript-and-use-javascript-from-flash-movies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

