With the advent of ActionScript 3.0 and Flash CS3, Adobe took out the possibility of direct access between AS2 and AS3 clips. The next option (besides communication through servers and web services) is local connection. Until now, if you’d create a clip in Flash MX2004 or Flash 8, using AS2, and inside that clip you would load another .swf file (that too created with AS2), both clips would be able to have access to each other’s objects and functions. This is not the case anymore with the new AS3 files. An AS3 clip will not be able to access any objects or functions defined in the AS2 file that it has loaded, and the loaded AS2 file will not be able to access objects and functions defined in its’ parent, the AS3 clip. The only way for the two movie clips to communicate is to use the LocalConnection class. For an unexperienced user this could be a little troublesome: loading the AS2 file, verifying that it’s been correctly loaded, creating LocalConnection objects in both files and trying to connect them in order to be able to execute functions defined inside those files and on the objects existing in those files.

For this reason we developed the ActionScriptBridge components (ASBTerminal for AS2 and ASBContainer for AS3), to ease the work needed to be done so the two AS2 and AS3 movie clips could communicate. The user has only to drag and drop an instance of the components in the AS2 and AS3 clips, define the functions he needs to call and use the run method of the components to call the defined functions.

Now this is still a beta version, but it’s working pretty well. The ASBContainer loads an external AS2 .swf file and the two clips attempt to communicate with each other using LocalConnection objects. The user has only to set the instance names for the two component instances and set the source file to the ASBContainer instance. All the rest is done by the two components: loading the AS2 file and initiating the communication. The connection name for each of the LocalConnection objects is set automatically by the ASBContainer instance. Each connection has a uniquely generated name, encrypted using MD5. Once the ASBContainer has established a communication channel with the ASBTerminal instance, it will not accept any other connection. Each ASBContainer instance should load its’ own AS2 file and there shouldn’t be two ASBContainer instances loading the same file.

Further development will depend on user feedback on this project, so any ideas or comments are welcome.

18 Responses to “Interaction between ActionScript 2.0 and ActionScript 3.0 within the same project”

  1. raulpopa says:

    G. Skinner just released a class based bridge called SWFBridge, very nice, but more hardly to use, so if you want to check it out, here is the link.
    http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html

    The SWFBridge is a small work around the LocalConnection class, so they have few mistakes inside their bridge, like these:
    1. you can’t open the same swf for more than 1 time on one single machine, not in different browsers not even in the same AS3 project, because of their method of using manual setting for connection including a connectionID
    2. you can’t expect returns from methods you call
    3. you can’t call methods anywhere inside the AS2.0 movie, because you don’t have the scope parameter nor the run command methods.

    ActionScriptBridge solved all these problems, and it is the best tool to load AS2.0 content inside AS3.0 projects and use it to communicate back and forth properly.

  2. freddy says:

    I’ve seen a bug with focus between as2 and as3

  3. negush says:

    Hi freddy,

    As I mentioned, this component is still a beta version, so it is possible for bugs to exist. But it would really help us to know exactly what the bug is about.

    Thanks.

  4. freddy says:

    well… I’m working with Gmap AS2 component (http://www.afcomponents.com/components/g_map/) into a as3 movie with dropdown and textfileds iu components… when the as2 movie get the focus it’s imposible write in the textfiled(as3) for example because the foucs jump to the as2 movie

  5. freddy says:

    I’m gettin the same trouble with the gskinner class… maybe a localconnection bug?

  6. freddy says:

    ok… the problem is when the as2 movie get the focus and then you try to get the focus in the as3 movie… the as2 movie don’t less the focus

  7. raulpopa says:

    I’m sure this is a common issue, it is a Flash Virtual Machine issue, somehow, it acts a bit of this. VM2 focuses and loses focus for VM1, but the VM1 does not even know that it is loaded inside a VM2 movie, and it is not able to lose focus unless you step out of the the entire flash movie or if you reload the as2 content.

    There should be some fscommand that you could use to get the focus on the AS3 movie again… from the as2 movie.

    You should write to Adobe about this issue, since it is their issue.

  8. Wigz says:

    Just set GMap.enabled = false; and it should work fine. This will disable focus manager for GMap, but nothing else will be effected.

  9. shane says:

    Hi,

    i m updating my e-learning course player project with Flash cs3 and AS3.0. the old version of course player was in As2.0. which load cousre swf files .
    it was working fine Flash8 As2.0.
    the player load course swf. the loaded course swf on a specifec frame call a method like this
    _level0.setButton(2) method from course player;
    The setButton(parameter) method defination is in new courser player. the loaded movie which is in Actionscritp2.0 not finding this method
    in new course player which in Actionscript3.0. its working well with the old course player.
    can any one give me solution to solve the issue.

    i can’t make changes in course swf files b/c there are thousand of course files.
    i have used your nice component and also local connection classes
    but both are two way communication, so i have make changes in thousand of swf files of my cousrer ???

    regards

  10. Rajesh says:

    Hi,

    Its a very nice component. I am using this into our project.But there are few issues I am still facing it.

    1) Focus issues between as2 swf and as 3 swf.
    2) I have made connection between swf created using Flex and
    Flash 8. Communication happens only one way i.e. from AS 3 to AS 2
    but it is not happening the other way. How can i work around that.

    mxml code(hostAS3.mxml)
    ———————–

    public var uiComponent:UIComponent;
    public var conn:ASBContainer;

    private function initApp():void
    {
    uiComponent = new UIComponent();
    conn = new ASBContainer();
    conn.x = 100;
    conn.y = 100;
    conn.source = “myAS2.swf”;
    conn.boudingBox_mc.visible = true;

    conn.addEventListener(ASBEvent.INIT,initHandler);
    conn.addEventListener(ASBEvent.STATUS,statusHandler);
    conn.addEventListener(ASBEvent.CONNECT,connectHandler);
    conn.addEventListener(ASBEvent.ASB_RETURN,returnHandler);
    conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR,asyncErrorHandler);

    uiComponent.addChild(conn);
    this.addChild(uiComponent);
    }

    public function asyncErrorHandler(aSyncEvt:AsyncErrorEvent):void
    {
    trace(“asyncErrorHandler”+aSyncEvt.text);
    }

    private function initHandler(event:ASBEvent):void
    {}

    private function statusHandler(event:ASBEvent):void
    {
    try
    {
    switch(event.level)
    {
    case “error”:
    trace(“Error in connecting”);
    break;

    case “status”:
    //conn.visible = false;
    trace(“Succeeded in connecting”);
    break;
    }
    }
    catch(err:Error)
    {
    trace(” error message “+err.message);
    trace(” “+ err.getStackTrace());
    }
    }

    private function connectHandler(event:ASBEvent):void
    {
    trace(“AS 3 -> in connectHandler”);
    conn.run(“test()”);
    }

    private function returnHandler(event:ASBEvent):void
    {
    Alert.show(“AS 3 -> returnHandler”);
    }

    public function callAS3():void
    {
    Alert.show(“Called from AS 2”);
    }

    //AS 2 code(myAS2.fla)
    ————
    var as2As3BridgeComp:MovieClip = null;
    var ASBTerminal_comp:MovieClip = null;
    ASBTerminal_comp = as2As3BridgeComp.attachMovie(“ASBTerminal”,”ASBTerminal_comp”,this.getNextHighestDepth());

    ASBTerminal_comp.addEventListener(“status”,statusHandler);
    ASBTerminal_comp.addEventListener(“asb_return”,asbReturnHandler);

    function test():Void
    {
    trace(“Calling from Flex”);
    }

    this.createClassObject(mx.controls.Button, “btnCallAS3″, this.getNextHighestDepth(),{label:”btnCallAS3”});
    btnCallAS3.addEventListener(“click”,btnCallAS3Click);

    function btnCallAS3Click()
    {
    trace(“btnCallAS3Click”);
    ASBTerminal_comp.run(“callAS3()”);
    }

    when i run this code it throws me error:
    Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.LocalConnection was unable to invoke callback getAndPass. error=ReferenceError: Error #1069: Property hostAS3_0 not found on _hostAS3_mx_managers_SystemManager and there is no default value.

    Please help me out…How I can solve this

  11. Rajesh says:

    I think it is something with the scoping issue in Flash. I am not sure what is wrong.I have properly included swc inside Flex by putting an instance of ASBContainer onto stage and publishing it as a swc. Also I have included ASBTerminal inside AS 2 code. I m not sure what is wrong but I have to solve this asap.Thanks

  12. Rajesh says:

    btw I am using Flex 2.0.1 and Flash 8 professional version.

  13. 194c01583a17 says:

    194c01583a17…

    194c01583a17bdac4959…

  14. Paul says:

    This is a great component. As far as I tested it, it seems to suit me very well.
    Thank you so much, it saves me so much trouble 🙂
    Keep up the good work

  15. Ashli Shay says:

    Sick of getting low numbers of useless traffic for your website? Well i wish to let you know about a brand new underground tactic that produces me personally $900 per day on 100% AUTOPILOT. I could truthfully be here all day and going into detail but why dont you simply check their site out? There is really a excellent video that explains everything. So if your seriously interested in producing easy hard cash this is the website for you. Auto Traffic Avalanche

  16. Tisha Gonce says:

    Do you mind if I quote a few of your articles as long as I provide credit and sources back to your webpage? My blog is in the exact same area of interest as yours and my visitors would really benefit from a lot of the information you present here. Please let me know if this alright with you. Thanks!

  17. Draw poker will be the traditional kind of
    poker and was played prolifically in high stakes cash games within the nineteenth century and early twentieth century.
    The Popularity of On line Poker – These days, online poker has changed into a popular option,
    making poker playing an available choice to a person with
    a laptop as well as an internet connection. Many top players advise against multi-tabling
    in any way, especially within the case of newer players, who should be focusing intently on staring at the players at their table,
    and paying close attention to exactly what happens.

  18. If you are playing online slots using real keep for sure,
    you should pay attention to some of this back you finally fail to bring house the victory.
    In this advanced mature you can law online slots in relation to
    everywhere, even to make transactions you can along with use online bank transfers
    or even on some sites you can create deposits using credit.

    Some things that you have to pay attention to are actually quite
    common, but people often ignore them and underestimate them, hence in the stop what happens is that the person loses all of the
    initial capital to bet. correspondingly you
    should begin reading anew and listening to some of the once that will
    make you skillful to enjoy online slot games without distressing
    virtually losing.

Leave a Reply