Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / July 2008



Tip: Looking for answers? Try searching our database.

Loading an AS2 Swf into an AS3 project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rritchey - 24 Jun 2008 14:32 GMT
I have a need to be able to load legacy AS2 SWF's into a new AS3 project.  I
know that this is not readily possible, because you can only communicate
between the two via the LocalConnection class.  So, what I have done is to
create an AS2 proxy SWF.  This SWF will handle the loading of all legacy SWF's
and act as a middleman to pass the function calls between the pre-compiled SWF
and the new SWF using the LocalConnection class.  The new SWF also needs to be
able to load AS3 SWF's, though.

Because of this, I have the need to detect the AS version of the loaded SWF.  
If 1 or 2, then change the source to the AS2Proxy.swf, if 3 then simply load it.

I have written the following code.  My problem comes in when the init event
fires.  Regardless of the compiled version of the loaded SWF, it always traces
3 as the AS version.

simulation.source = ModulePath+curPageXML.attribute("Path").toString();
   
simulation.addEventListener(Event.INIT,doInitSim);

function doInitSim(evt:Event):void {
    trace(simulation.loaderInfo.actionScriptVersion); // always traces 3
    if(simulation.loaderInfo.actionScriptVersion > 2){
        simulation.addEventListener(Event.COMPLETE,doVideoReady);
    }else{
        simulation.source = InterfacePath+"AS2Proxy.swf";
        simulation.addEventListener(Event.COMPLETE,doProxyReady);
    }
}
rritchey - 24 Jun 2008 15:21 GMT
Alright, I solved this problem, only to come up with many more.

To solve this problem, I needed to point to the loaderInfo object of the
UILoader's content.  So: simulation.content.loaderInfo.actionScriptVersion.

Now the proxy loads correctly, but I start getting errors immediately.  Let me
paste some code to show the next steps:

First off.  I immediately receive a StatusEvent error, though the path gets
sent into the proxy and loads correctly.

Next, when the complete event fires in the AS2 SWF - it sends a completion
back up to let the AS3 SWF know that it finished (and any handling that needs
to happen at that point.)  I receive the following error:
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095:
flash.net.LocalConnection was unable to invoke callback loadSwf.
error=ReferenceError: Error #1069: Property loadSwf not found on
com.applied.flash.events.AS2Connect and there is no default value.

This is the AS2Proxy.swf code.

var connection:LocalConnection = new LocalConnection();

connection.connect("AS3Connect");

if(path){
    proxyLoader.contentPath = path;
}

connection.loadSwf = function( path:String ){
    proxyLoader.contentPath = path;
}

proxyLoader.complete = function(){
    connection.send("AS3Connect","swfLoaded",true);
}

function completion():Void {
    connection.send("AS3Connect","swfLoaded",true);
}

This is the AS2Connect class for hearing what is sent from the AS2 SWF

package com.applied.flash.events {
   
    public class AS2Connect extends Object {
       
        public function swfLoaded( value:Boolean ):void {
            trace(value);
        }
    }
}

Finally, this is all of the related code in the AS3 swf

var connection:LocalConnection = new LocalConnection();
var myIP:String = connection.domain;
connection.client = new AS2Connect();
try{
    connection.connect("AS3Connect");
}catch(e){ }

simulation.source = ModulePath+curPageXML.attribute("Path").toString();
contentPlayers.addChild(simulation);
simulation.addEventListener(Event.INIT,doInitSim);

function doInitSim(evt:Event):void {
    if(simulation.content.loaderInfo.actionScriptVersion > 2){
        simulation.addEventListener(Event.COMPLETE,doVideoReady);
    }else if(simulation.source != InterfacePath+"AS2Proxy.swf"){
        simulation.source = InterfacePath+"AS2Proxy.swf";
        simulation.addEventListener(Event.COMPLETE,doProxyReady);
    }
}

function doProxyReady(evt:Event):void {
    connection.send("AS3Connect","loadSwf",
ModulePath+loadedXML.Pages.Page[tree.selectedIndex].attribute("Path").toString()
);
    connection.addEventListener(StatusEvent.STATUS,doStatus);
}

function doStatus(evt:*){
trace(e);
}
rritchey - 10 Jul 2008 15:12 GMT
rritchey - 14 Jul 2008 14:34 GMT
bump
rritchey - 16 Jul 2008 13:32 GMT
Two bumps and no replies, so I have moved my query to the
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=665&threadid=
1377398&CFID=4594815&CFTOKEN=b9da2b8c7f8ac502-2BD544B7-0317-8A0D-9B9F409C1651D00
A&jsessionid=121220fe8f4b00efd56d2c42171a1ca65129
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.