Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2009-04-16
Medium Priority
Last Modified: 2013-11-11
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.

Question by:bham3dman
  • 3
  • 2
LVL 11

Accepted Solution

ugeb earned 2000 total points
ID: 24163056

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
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


Look up ExternalInterface in the index under 'E' (naturally :)   It's in the flash.external package.




Author Comment

ID: 24176600
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 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");
    <form id="form1" runat="server">
    <script type="text/javascript">
        var currentPage="Home";
        function setCurrentPage(newPage) {
            currentPage = 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");
  <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">
       <p>Alternative content</p>
        <!--[if !IE]>-->
----------actionscript 3----------
import flash.external.*;  
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str):void {
     txtStr.text = str;

Open in new window

LVL 11

Expert Comment

ID: 24176994
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.

Author Comment

ID: 24177830
Thanks.  I'll try to implement the full example tomorrow.

Author Closing Comment

ID: 31571194
I am sorry for the delay in accepting this.  Thank you for the help.  

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question