Here is an example of sending data from JavaScript to ActionScript 3 and vice versa:

You can make Flash-ActionScript send and receive data from JavaScript and vice versa. I show html code to javascript code that allows you to transfer information.
\u0026lt;! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
\u0026lt;html> ;
\u0026lt;head> \u0026lt;title> bidirectional shipping \u0026lt;/ title>
\u0026lt;/ head>
<body>
<table style="border: 0; cellspacing: 0;cellpadding: 0;">
<tr>
<td>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" allowScriptAccess="always" allowNetworking="all" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="150" height="150" id="EnvioDatos" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="EnvioDatos.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#CCCCCC" />
<embed src="EnvioDatos.swf" quality="high" bgcolor="#CCCCCC" width="150" height="150" name="EnvioDatos" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_es"></embed>
</object>
</td>
<td style="background-color:#EAEAEA;width: 150px; height: 150px; vertical-align: top; "width =" 150 "height =" 150 ">
\u0026lt;form method="post" action=""> JavaScript \u0026lt;br/>
\u0026lt;input id =" valorEnvio "type =" text "name =" valorEnvio "size =" 10 "> \u0026lt;input type="button"
value="enviar" onclick="enviaDatos();"> \u0026lt;br/> \u0026lt; br /> Posted by \u0026lt;br/>
ActionScript: \u0026lt;br/>
\u0026lt;input id = "valorEnviadoPorAS" type = "text" value = "" name = "valorEnviadoPorAS" disabled> \u0026lt;/ form> \u0026lt;/ td>
\u0026lt;/ tr>
\u0026lt;/ table>
\u0026lt;script type="text/javascript">
function getFlashMovie (movie name) {
was isIE = navigator.appName.indexOf ("Microsoft")! = -1 ;
return (isIE)? window [movie name]: document [movie name];}
function javascriptRecibe (cadena) {
was myValorEnviadoPorAS = document.getElementById ('valorEnviadoPorAS');
myValorEnviadoPorAS.value = cadena;
}
enviaDatos function () {
was myValorEnvio = document.getElementById ('valorEnvio');
getFlashMovie ("EnvioDatos"). flashRecibe (myValorEnvio.value);
} \u0026lt;/ script>
\u0026lt;/ body>
\u0026lt;/ html>
getFlashMovie function, permtie in ancient Explorer browsers get a JavaScript reference the Flash object.
javascriptRecibe function is called from ActionScript with the help of ExternalInterface.call function.
ExternalInterface.call (javascriptRecibe "txtValorEnvio.text)
enviaDatos function gets a reference to Flash object by the name used in the document HTML EnvioDatos "and calls the registered flashRecibe function in ActionScript ExternalInterface.addCallback
ExternalInterface.addCallback (flashRecibe" flashRecibe)
package {import
flash.display.MovieClip;
flash.external.ExternalInterface import, import
flash.text.TextField;
flash.events.MouseEvent import;
/ **
* ... Liling
* @ author * / public class
EnvioDatos extends MovieClip {public var
txtValorEnviadoPorJS: TextField;
public var txtValorEnvio : TextField;
public var btnEnviar: MovieClip;
EnvioDatos
public function () {
btnEnviar.addEventListener (MouseEvent.CLICK, enviaDatos)
ExternalInterface.addCallback (flashRecibe "flashRecibe);}
enviaDatos public function ( event: MouseEvent) {
ExternalInterface.call (javascriptRecibe "txtValorEnvio.text);}
flashRecibe public function (value: String) {
txtValorEnviadoPorJS.text = value;
}}}
The ActionScript code is similar but as mentioned earlier with line:
ExternalInterface.addCallback (flashRecibe "flashRecibe)
establish the function in ActionScript that is going to take to meet the request comes from JavaScript.
enviaDatos function makes a direct call to javascriptRecibe function with an argument that has been sending data through ActionScript function ExternalInterface.call
ExternalInterface.call (javascriptRecibe " , txtValorEnvio.text)
I hope this example will be useful.
No comments:
Post a Comment