Link to home
Start Free TrialLog in
Avatar of bham3dman
bham3dman

asked on

How do I send and retrieve variables between Actionscript 3 and Visual Basic.net?

Greetings Experts,

I need assistance understanding the basics of exchanging variables between a Flash .swf (actionscript 3) and a vb.net webpage.  I just need to exchange simple variables and I'm looking for the simplest solution as I am still learning both.

Code examples would be very helpful.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of ugeb
ugeb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bham3dman
bham3dman

ASKER

Hi Gene,

Thanks for the response.  I did run across the ExternalInterface documentation in my initial search but  I'm afraid that I need a little more direction.  In my quest to figure this out, I've run across the code below but can't get it to work.

I'm using swfObject to embed my swf and that works fine.  However, when I click the Home link, Flash isn't receiving the data from Javascript.

In the actionscript, I have a couple of items - a movie clip that changes color and a dynamic text object to display the variable passed in. However, the function is never called.

Any assistance is much appreciated.
-----------html----------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="scripts/swfobject.js"></script>
    
    <script type="text/javascript">
        swfobject.registerObject("myId", "9.0.0", "flash-java.swf");
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <script type="text/javascript">
        var currentPage="Home";
        function setCurrentPage(newPage) {
            currentPage = newPage;
            SendDataToFlashMovie(newPage);
        }
 
        function getFlashMovieObject(movieName){
            if (window.document[movieName]){
                return window.document[movieName];
            }
            if (navigator.appName.indexOf("Microsoft Internet")==-1){
                if (document.embeds && document.embeds[movieName])
                return document.embeds[movieName];
                }
            else // if (navigator.appName.indexOf(Microsoft Internet)!=-1)
            {
                return document.getElementById(movieName);
            }
        }
 
        function SendDataToFlashMovie(newPage)
        {
            var flashMovie=getFlashMovieObject("myID");
            flashMovie.sendTextToFlash(newPage);
        }
    </script>
    
<div>
  <a href="javascript:void(0);" click="setCurrentPage('Home')">Home</a>
    
  <object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550" height="400">
 
    <param name="movie" value="flash-java.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="flash-java.swf" width="550" height="400">
       <!--<![endif]-->
       <p>Alternative content</p>
        <!--[if !IE]>-->
     </object>
     <!--<![endif]-->
   </object>
</div>
 
</form>
</body>
</html>
 
 
----------actionscript 3----------
import flash.external.*;  
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
 
function getTextFromJavaScript(str):void {
     txtStr.text = str;
     mcColor.gotoAndStop("2");
}

Open in new window

You may be having a security issue.

You need to implement the example in the documentation I linked to above.  It will show you how things work and will alert you to security issues if you're having them.
Thanks.  I'll try to implement the full example tomorrow.
I am sorry for the delay in accepting this.  Thank you for the help.