• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 924
  • Last Modified:

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!
0
bham3dman
Asked:
bham3dman
  • 3
  • 2
1 Solution
 
ugebCommented:
Hi,

You have a couple of options in getting a swf to talk to the outside browser world.  

1) call a php web page -- may not want to do this if you're doing vb.net
or
2) use ExternalInterface to call a JavaScript function.

You probably want to do #2.  Have the AS code call a JavaScript function that communicates the variables to the vb.net page.  

The adobe help for ExternalInterface includes a useful example

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html

Look up ExternalInterface in the index under 'E' (naturally :)   It's in the flash.external package.
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/external/package-detail.html

HTH

Gene


0
 
bham3dmanAuthor Commented:
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

0
 
ugebCommented:
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.
0
 
bham3dmanAuthor Commented:
Thanks.  I'll try to implement the full example tomorrow.
0
 
bham3dmanAuthor Commented:
I am sorry for the delay in accepting this.  Thank you for the help.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now