Well, most of you may not remember the post made by Danial.Beta about his creation (per say, with the help of Elation) about how to send data to Flash ActionScript (AS) 1 and 2 back in id:469539
As you might figure out, this doesn't work for AS3... so I modified that snippet to make it work!
What's so special about this? Well... now you can also make Flash AS3 interact with the JavaScript in that browser with a simple function! No horrendous work-around to make Flash >> DM!!!
So here we go: NOTE: THIS IS NOT A PLUG-AND-PLAY TYPE OF THING, NEED TO MAKE MINOR CHANGES AND ADD TO AS3
The above is for ActionScript (AS) 1 and 2, which no longer works for AS3.
I have modified the above to make it work for AS3:
mob/proc/flash(filename, Val, width, height, BrowserOptions, Function="sendvar", bgcolor="#000000", quality="high", align="middle")
if(src.client)
var/filenameshort=copytext("[filename]",1,findtext("[filename]","."))
src<<browse_rsc(filename)
src<<browse({"
<html>
<head>
<SCRIPT type=text/javascript>
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window\[movieName];
} else {
return document\[movieName];
}
}
function var2flash() {
[Val?"thisMovie('[filenameshort]').[Function]('[Val]');":""]
}
function ASdata(val) {
alert(val);
}
</SCRIPT>
</head>
<body onLoad="var2flash()">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="[width]" height="[height]" id="[filenameshort]" align="middle">
<param name="allowScriptAccess" value=" sameDomain" />
<param name="bgcolor" value="[bgcolor]" />
<param name="movie" value="[filename]" />
<param name="quality" value="[quality]" />
<embed src="[filename]" quality="[quality]" bgcolor="#[bgcolor]" width="[width]" height="[height]" name="[filenameshort]" align="[align]" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
"},BrowserOptions) |
But that's not all, we still have to set up Flash AS3 to receive the data we just sent:import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendvar", JSdata);
ExternalInterface.call("ASdata", "Flash AS3 works :D");
function JSdata(value:String) {
this.name_field.text=value;
} |
In addCallback: - You need to change "sendvar" to the value of Function in the JS as you defined in the argument (which, by default, is sendvar). - JSdata is the name of the function called when receiving data from JS. Change it to whatever name you see fit but remember to make the appropriate changes.
As for call(), it will call the function "ASdata" back in JavaScript.
What to do in this snippet: - You may want to remove, or change, ASdata() in the JavaScript in the first snippet.
- Use call() whenever you want to send data to JS.
- Have fun :D
The above snippet has been added to the Snippets Database :D |
|