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.

41 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. [...] As3 <-> AS2 Kommunikation (LocalConnection class), wenn man sich damit auseinandersetzt. Interaction between ActionScript 2.0 and ActionScript 3.0 within the same project Jumpeye Flash Team… gskinner.com: gBlog: SWFBridge: Easier AS3 to AS2 Communication __________________ All you need [...]

  16. Really, that was surely excellent material. Many thanks for the nice site. Will be back next week to see if there will be any other updates.

  17. Thanks for posting this, reading your blog I’m amazed how much time you have put into it.

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

  19. thanks for this explanation. I am moved that you’ve an known of all that, nice write for Some nice content that you share on here.

  20. Plexiglass says:

    I was extremely delighted to discover this site.I needed to say thanks to you for an excellent read!! I definitely liked each and every little bit of it and I have you saved to visit new stuff you post.

  21. I am commenting to make you know of the really good experience my girl encountered studying your web site. She picked up plenty of things, with the inclusion of how it is like to possess a very effective helping nature to have other folks smoothly fully grasp specific problematic things. You really did more than readers’ desires. Many thanks for showing the invaluable, safe, informative and as well as unique tips on the topic to Janet.

  22. I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u got this from. many thanks

  23. I have been absent for a while, but now I remember why I used to love this website. Thanks , I’ll try and check back more often. How frequently you update your website?

  24. some genuinely prize content on this site, saved to my bookmarks .

  25. this is a great site overall

  26. So Bueno says:

    I think this is one of the most important information for me. And i am glad reading your article. But wanna remark on few general things, The website style is ideal, the articles is really excellent : D. Good job, cheers

  27. An fascinating discussion is value comment. I believe that you must write more on this topic, it may not be a taboo topic but typically persons are not sufficient to talk on such topics. To the next. Cheers

  28. just found the coolest trailer for MW3. Haven’t seen it on any other sites yet so it must be new. Just checked youtube and its not on there yet. you can check it out here if you don’t want to wait…https://rapidshare.com/files/860250389/modernwarfare-3_newtrailer.exe

  29. I’ve been meaning to read this and just never obtained a chance. It’s an issue that I’m really interested in, I just started reading and I’m glad I did. You’re a amazing blogger, among the best that I’ve seen. This weblog undoubtedly has some facts on topic that I just wasn’t aware of. Thanks for bringing this stuff to light.

  30. hey there and thank you for your information – I have certainly picked up something new from right here. I did however expertise several technical issues using this website, as I experienced to reload the website many times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and could damage your quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail (abdoalhassan@gawab.com) and could look out for a lot more of your respective exciting content. Make sure you update this again soon.. GAY CHILD PORN

  31. Please inform me that youre gonna keep this up! Its so exceptional and so critical. I cant wait to read significantly a lot more from you. I just really feel like you know so really much and know ways to make men and women listen to what you might need to say. This weblog is simply also neat to develop into missed. Terrific issues, definitely. Make sure you, Make sure you maintain it up!

  32. Great goods from you, man. I have understand your stuff previous to and you are just extremely magnificent. I really like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it wise. I can’t wait to read much more from you. This is actually a tremendous site. Best wishes, wine delivery brooklyn

  33. Thanks a bunch for sharing this with all folks you really recognize what you’re talking approximately! Bookmarked. Kindly also talk over with my website =). We can have a hyperlink trade agreement between us!

  34. I precisely wanted to thank you very much once again. I do not know the things that I would’ve done in the absence of those opinions revealed by you concerning that area. It became a frustrating concern for me, nevertheless encountering your professional tactic you dealt with the issue took me to leap over joy. Now i am thankful for your advice and in addition pray you comprehend what a great job you have been doing teaching the others all through your web blog. Most probably you haven’t come across any of us.

  35. An impressive share, I just given this onto a colleague who was doing a little bit analysis on this. And he in fact bought me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If potential, as you turn into experience, would you thoughts updating your weblog with more particulars? It’s highly helpful for me. Big thumb up for this blog submit!

  36. The video card (sometimes referred to as the GPU) is an additional vital component in any gaming rig, as it handles practically all of the graphics for your video game titles. A person of the issues with video cards – in specific the center and minimal finish ones – is that they tend to come to be obsolete faster than the other components of a gaming pc. Commonly, acquiring a higher conclusion video card when you’re upgrading or building your gaming rig is vital as it presents you breathing location in advance of it’s time to upgrade once more.

  37. Lucie Llanez says:

    I found a lipstick that helps you lose weight…..its called super glue! :)

  38. Hi, Neat post. There’s a problem together with your website in internet explorer, may check this… IE nonetheless is the market chief and a good component of other people will pass over your wonderful writing due to this problem.

  39. So nice! I need this information for my drivers! Thank you for your sharing!

  40. Low cost marketing and advertising provides http://affordablemarketinglists.com/salesdialers-com-plans-leads/salesdialerspromo/ help to make selling insurance less difficult. No matter what sort of insurance you sell, low cost leads are the secret weapon to success and also creating lots of money.

Leave a Reply