From DM to Flash to DM in under 60 minutes.
By Danial.Beta

Introduction:

This has been the question of about a million people directed at me. "How did you make Flash talk with Dream Seeker in FlashChat?"
The answer to that is actually quite simple. It works almost exactly like HTML links to Dream Seeker. You simply make Flash call links in the format of "byond://?variable1=Something&variable2=Something else". Rather simple, but I understand you don't all know how to work Flash and the Topic() proc. So I will break it down.

 

Part One: Basic HTML communication.

We are starting here because it is important to understand the Topic() proc before attempting anything else in this tutorial. I will do a quick rundown to get you understanding it.

From the reference:

mob/Login()
    src << "Click <a href=?source>here</a> to download the source code."
    return ..()

client/Topic(href)
    if(href == "source")
      usr << file("world.dm")
      usr << file("world.rsc")
    else ..() 

Lets break that down a bit.


 	src << "Click <a href=?source>here</a> to download the source code."

That is saying, basically, make a link that sends "source" to DreamSeeker, which then has to process this information. This is where client/Topic(href) comes in.

    if(href == "source")

Is asking if the link says source, basically. To expand on this, if we added the line "usr << href" after the client/Topic() we would have "source" print out. Could use this basis to return a simple variable. We need a bit more.We will need a few variables, in this case, we will just have href be a list. A simple link like <a href="?source=test">here</a> and a small Topic() change.

mob/Login()
    src << "Click <a href=\"?source=test\">here</a> to download the source code."
    return ..()

client/Topic(href,href_list[])
    if(href_list["source"] == "test")
      usr << file("test.dm")
      usr << file("test.rsc")
    else ..() 

Simple enough? Using this format we can have any number of links. <a href="?source=test&variable2=another test">here</a> is a good example of a link with multiple variables passed.

 

Part Two: Making it work with Flash

As you might have already guessed, nothing is that simple. It took me a good bit of experimentation to figure this out, but the links wont work in the standard ?variable format. instead you need something a little more. Basically, you just add the byond:// before it. so ?variable for a HTML link would be byond://?variable.

on (release) {
    getURL("byond://?source=test");
}   

That is a basic link in Flash. I am assuming you know a bit about flash to make this work. Using this basic knowledge, I created FlashChat. The entire Chat is based around this. So good on it. We now have the secret of FlashChat broken. But...

 

Part Three: Talking to Flash!

I realize that most of you don't think this is so amazing, but it really is. Being able to get DreamSeeker to talk to Flash and to have Flash talk to DreamSeeker means two way communication. I have known for a long time that it was probably possible, but I never got around to doing the research to get it done. I knew the key was to have DreamSeeker generate some JavaScript that Flash would use for a variable, but I never liked JavaScript and lost motivation to do it. Elation finally got around to it and after a quick explanation of his work, I was able to replicate it with extreme success.

It works very simply. You have BYOND generate the HTML and JavaScript required to show the flash and set the variable. Lets say you wanted to set a variable to show a simple Hello World message. Lets start by creating a test Flash file, we will name it test.fla. Create a simple text box in the center, set it to dynamic and the variable as "testvar".Do a "Control>Test Movie." Now we do a "browse()" as follows:

var/filename = 'test.swf' //The flash file
var/V = "Hello World" //This is the variable to be passed
var/width //Width of the flash movie
var/height //Height of the flash movie
var/filenameshort=copytext("[filename]",1,findtext("[filename]",".")) //This generates the short filename needed
browse({"
<html> <head> <SCRIPT type=text/javascript> var sendID function var2flash() { window.document.[filenameshort].SetVariable("testvar", "[V]"); } </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="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> "}

This may seem like a lot, but it is actually quite simple. The function var2flash() sets the variable "testvar" in Flash to whatever V is. All the rest of that stuff is to have flash show up and have it at the right size. You could use this process to send 50 variables into flash, if you wanted to. The point is, that is all there is to it.

To simplify maters, I made this dirty little proc to make it easier for me to work with it. Remember, this is very simple, so don't expect it to work in all cases, and it is uncommented because I'm an idiot with my own work:

/* /////////////////////////////////////////////////////////////////  
/////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, var/height, var/O)
      if(filename && V && T)
          if(!width)
              width=550
          if(!height)
              height=400
          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 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="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)

And to finish this off, here is a zip file containing a basic hello world test.