A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Convert AS3 to AS2

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    19

    Convert AS3 to AS2

    I have a working movie file that I built using AS3. Problem is that I want to call an external swf file written in AS2. Particularly it is a quiz file created using the templates in flash cs3. Since the quiz is AS2 and my main file is AS3 I've been having problems loading the quiz file externally in the main fla file. So what would be the easiest way to make it work? Convert my AS3 file to AS2 and then load the file externally and hope that it will work? Or is there an easier way for what I want to do? The ideal would be to have my quiz file in my main FLA file on the click of a button.

    Any help is appreciated.

    Thanks in advance,

    Theo

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Not sure about easy, but the way most people communicate between AS 3 and AS 2 movies is through a localConnection.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Maybe you could instruct me on how to use localConnection? I just started using flash couple of weeks ago and I'm not familiar with Actionscript yet. Most of my coding was pasted and modified.

    Thanks again.

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Here's a link to Grant Skinner's swfBridge class - it's designed for exactly this problem.

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Thanks for the link, I will see it as soon as I get home.



    - Theo

  6. #6
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Can I follow the method described in the website locally? I get an error as soon as I paste the code into my files.

  7. #7
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Just to make it clearer, I don't want to load any functions. Just literally load the as2 file on top of everything on the as3 project on click of a button and be able to unload it again with the click of a button.

    Hope that makes sense.

  8. #8
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    If you don't ever need to communicate with the as2 swf you can just use this...example:

    PHP Code:
    import com.calypso88.SWF;

    var 
    mySWF:SWF = new SWF('http://calypso88.com/tester.swf');
    but1.addEventListener(MouseEvent.CLICKaddSWF);
    but2.addEventListener(MouseEvent.CLICKremSWF);

    function 
    addSWF(e:MouseEvent):void{
        
    addChild(mySWF);
    }

    function 
    remSWF(e:MouseEvent):void{
        
    removeChild(mySWF);


  9. #9
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    OK I found this code and made it work with one problem. When the frame is called by the button the as2 swf loads up properly and you can start taking the quiz. After the second question though it stops loading for some strange reason. Here is the code I used.

    I inserted this in the AS3 file:

    PHP Code:
    // ActionScript 3 file, AS3Loader.fla
    // local connection instance to communicate to AVM1 movie
    var AVM_lc:LocalConnection = new LocalConnection();

    // loader loads AVM1 movie
    var loader:Loader = new Loader();
    loader.load(new URLRequest("quiz.swf"));
    addChild(loader);

    // when AVM1 movie is clicked, call stopPlayback
    loader.addEventListener(MouseEvent.CLICKstopPlayback);

    function 
    stopPlayback(event:MouseEvent):void {
        
    // send stopAnimation event to "AVM2toAVM1" connection
        
    AVM_lc.send("AVM2toAVM1""stopAnimation");

    and this into the AS2 file:

    PHP Code:
    // ActionScript 2 file, AS2animation.fla
    // one movie clip animation named animation_mc on the timeline

    // local connection instance to receive events
    var AVM_lc:LocalConnection = new LocalConnection();

    // stopAnimation event handler
    AVM_lc.stopAnimation = function(){
        
    animation_mc.stop();
    }

    // listen for events for "AVM2toAVM1"
    AVM_lc.connect("AVM2toAVM1"); 
    Any ideas why this problem?

  10. #10
    Junior Member
    Join Date
    Nov 2008
    Posts
    3

    wow

    Exactly what I was looking for!

    Thanks!


  11. #11
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Does the code work for you perfectly? What are you doing with it exactly? I can't get this solved, it's so weird. The file loads and then after first quiz question I cannon click on the "next" arrow anymore which makes my quiz unable to move to the next question.

    These are my files. Check them out if you like:

    http://www.hiphop.com.cy/decayer/elearning/quiz.fla
    http://www.hiphop.com.cy/decayer/elearning/lab-2.fla

  12. #12
    Junior Member
    Join Date
    Nov 2008
    Posts
    19
    Guys anyone?

  13. #13
    Junior Member
    Join Date
    Nov 2007
    Posts
    27
    I'm having the same problem: I have several AS2 games that I want to be able to call from an AS3 swf.

    I tried calypso88, and I get the following error:
    TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@307649e9 to flash.display.MovieClip.
    at MethodInfo-62()
    and even though the loaded .swf file started executing, it stopped almost immediately (it went into an infinite loop). This, of course, does not happen when I run the loaded swf by itself or when I call it from an AS2 swf.

    What am I doing wrong?

    Mariana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center