Index · Preferences · Help
Announcements · BYOND Features · Bug Reports · Fixes and Features · Developer How-To · Code Problems · Design Philosophy · Creations · Classified Ads · Gaming · Computers & Technology · Community
Forum Search:

[Advanced Search]

[Messages in this Thread] [Show All (4)] [Return to Creations]

Author:GhostAnime [Posts]
Date:8/23/09 7:29 am
Topic:DM - Flash AS3 Interaction
Post ID:715684
Next ID:715703
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:

/*
/////////////////////////////////////////////////////////////////////////////
/////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, Function="sendvar", 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>
                <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

Messages in this Thread: [Show All (4)]

  DM - Flash AS3 Interaction GhostAnime (8/23/09 7:29 am)
      Re: DM - Flash AS3 Interaction DarkCampainger (8/23/09 10:17 am)
          Re: DM - Flash AS3 Interaction GhostAnime (8/23/09 2:00 pm)
              Re: DM - Flash AS3 Interaction DarkCampainger (8/23/09 3:10 pm)