ID:195031
 
An old snippet by Danial.Beta with Elation's help. Originally posted here

(I merely did a minor tweak that most people may not notice)

/* /////////////////////////////////////////////////////////////////
/////var2flash() proc for lib.
/////Created by Danial.Beta
/////With help by Elation
/////Description: The basic function of this is to allow communication
///// going from dreamseeker to a flash file. To be lib soon
///////////////////////////////////////////////////////////////// */

mob/Login()
..()
var2flash('test.swf', "This is a test", src,550,400,"window=Test;size=600x500")

proc/var2flash(var/filename, var/V, var/mob/T, var/width=550, var/height=400, var/O)
if(filename && V && T)
var/filenameshort=copytext("[filename]",1,findtext("[filename]","."))
T<<browse_rsc(filename)
T<<browse({"
<html>
<head>
<SCRIPT type=text/javascript>
var sendID
function var2flash() {
window.document.
[filenameshort].SetVariable("sendvar", "[V]");
}
</script>
</head>
<body disabledLoad="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="movie" value="
[filename]" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="[filename]" quality="high" bgcolor="#ffffff" width="[width]" height="[height]" name="[filenameshort]" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
"}
,O)
DM-->Flash

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:

/*
/////////////////////////////////////////////////////////////////////////////
/////var2flash() proc for lib. /////
/////Created by Danial.Beta /////
/////With help by Elation /////
/////Modified by GhostAnime for ActionScript 3 on 8/23/2009 /////
/////Description: The basic function of this is to allow communication /////
///// going from dreamseeker to a flash file. To be lib soon/////
/////////////////////////////////////////////////////////////////////////////
*/


mob/proc/flash(filename, Val, width, height, BrowserOptions="window=browser", Function="sendvar", JSfunction, CSS="body{background-color: black;vertical-align: middle;}", bgcolor="#000000", quality="high", align="middle") // This is a flash-browser. Options = browser window options
if(src.client)
var/filenameshort=copytext("[filename]",1,findtext("[filename]","."))
src<<browse_rsc(filename)
src<<browse({"
<html>
<head>
&lt;style&gt;
[CSS]&lt;/style&gt;
<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);
}
[JSfunction]
</SCRIPT>
</head>
<center>
<body disabledLoad="var2flash('
[Val]')">
<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>
</center>
</html>
"}
,BrowserOptions)


Explanation of the arguments:
- filename is actually the reference to the flash file
- Val is what you want to send to the Function defined in Flash (by default, the Function is sendvar())
- width and height is the size for the flash video.
- BrowserOptions should be self-explanatory
- Function is the name of the function you want called on flash with the value of Var being sent (by default, this is sendvar)
- JSfunction is any extra javascript functions you want to define.
- CSS, bgcolor, quality and align should be self explanatory.

Here's another example using named arguments:
var/Jfunc = {"
function ASdata(){
alert("Meh");
"}


X.flash('Test.swf', "Hi", Function="DataSentByJS", JSfunction = Jfunc)



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 ExternalInterface.call() whenever you want to send data from Flash to JS.
- Have fun :D


EDIT:
Now in BYOND, you can call a specific javascript procedure defined and send information to the flash. Note you cannot do this immediately after displaying the flash file, you need to sleep(1+) it!

X.output("Data to send!","browser_ID:JSdata")  //  calls the Javascript function JSdata() defined in the browser earlier

<hr>
<hr>
<hr>
Flash -> DM interaction (unlike the previous section which is about DM -> Flash.)

To make Flash call client/Topic, you cannot use getURL() as it was in AS2 since it has been phased out in AS3.

Instead, you need to do the following (where you car replace the variable names, such as send_url, with what you want):
//  You need these variables
var send_data:URLVariables = new URLVariables();
var send_url:URLRequest = new URLRequest("byond://?");
send_url.method = URLRequestMethod.GET;
var send_load:URLLoader = new URLLoader();

// Here is some example of variables to be sent.
// Sending the variables atk, def, mgk, name, color
send_data.atk = this.atk_text.text;
send_data.def = this.def_text.text;
send_data.mgk = this.mgk_text.text;
send_data.name = this.nameinput.text;
send_data.color = favcol.selectedColor;
send_data.command = "creation";

// Basically telling flash what to data send
send_url.data = send_data;

send_load.load(send_url);
// Actual submission call
navigateToURL(send_url, '_self');


Now you can use client/Topic to parse through what Flash had sent. In this case, setting the values of the variables sent to the mob's stats.

If you are wondering how it looked like in
AS2
, in the words of DarkCampainger:
getURL("?variable1=value1;variable2=value2",_self);

Yeah, you're not the only one who's mad about the phaseout >_<

So yeah... now you can modify client/Topic() to look for the information sent to you though the flash and do whatever you want :o