Can an actionScript2 app be used inside a AS3 app? - actionscript-3

I've inherited an AS2 app that has a lot of functionality. I need to embed this thing somehow in my AS3 app so I can execute function calls etc and basically control it. Has anyone ever tried something like this? I'm assuming I'll have to URLLoader the AS2 SWF into a MovieClip and take it from there.

AS3 SWF (AVM2 movie) can load AS2 movies (AVM1 movie) using the Loader class, but cannot access the methods/properties of it. The loaded AS2 movie will be of type AVM1Movie (and not MovieClip).
Livedocs page about AVM1Movie
The two movies can communicate with each other using the LocalConnection class. See sending data from avm2 to avm1

Grant Skinner has a very useful pair of classes that simplify AS3<->AS2 communications over LocalConnection. We've used it to great success.
http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html

Related

Issue loading external swf on main file with as3

Hi I'm new to Flash CS6 and and AS3 and I have been stuck on this iPad/Android restaurant menu I have been doing. I amm trying to load an external swf on my main swf but have been getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at cuisine/init()[C:\Users\PAO\Desktop\OZ\SWIPE\cuisine.as:32]
at cuisine()[C:\Users\PAO\Desktop\OZ\SWIPE\cuisine.as:22]
I got the code of the swipes from a tutorial I found online. in the different sections fo the menu I was planning to load different swfs because I couldn't get the code to work for all the sections at the same time.
like I said, I am new to as3 and I really don't understand all the coding so i'm really stuck at a dead end.
hoping a kind soul could help me get out of this rut. the files can be found here
It can be a bit unintuitive to load external SWFs, especially if you are new to AS3. If I remember correctly, a big problem can be that you need to wait for the ENTIRE swf to load before trying to access anything.
You should only try to access code from the external swf after the Event.COMPLETE event. see here for more info
I would also suggest use the Greensock loader instead since it's a bit simpler.
Hope that helps

Main menu on game

I have created a menu for my game with buttons and whatnot as a separate .fla file named Menu. My actual game is another .fla file called Game.fla. I was wondering what the best way would be of loading this menu before the game plays?
Thanks.
I would suggest that you create a .swc with your Menu.fla, and then just add that .swc to your Game.fla
If you are using CS6, make sure that you are setting linkage for any MovieClips you want to create instances of in your code.
In the actionscript settings on the library path tab, you can add a .swc that will be included into your .swf when compiling.
In your code, you can now create an instance and add to the display list :
// Assuming MainMenu was a movieclip with linkage set in your .swc
var mainMenu:MainMenu = new MainMenu;
addChild(mainMenu);
I should note that this does not load the .swc at runtime, it includes the .swc to your .swf at compile time. I would recommend this method over loading a .swf in most cases. Cases where I might not, is if there was a large amount of content that wasn't needed all at once. That would allow you to minimize the amount of memory you were using and reduce the .swf size of your main .swf so it loads quicker.
Anytime you are loading .swf's in at runtime you are adding another layer of complexity, so I'd not recommend it unless you do have a good reason to do so. From what you have described, this doesn't sound like a situation where I'd load an external .swf at runtime.
Load the swf output from Menu.fla and keep a check on the progressEvent from loader. Don't show the game screen until Menu.swf is completely loaded and initialized.
Some more details wrt comment from OP:
You can you http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load%28%29 to load external swfs. init Event would mark that the swf's actionscript has started executing. OTOH, complete event would tell that all the swf bytes have been loaded.

FLASH : get inputtext value in AS2 SWF that running/load from AS3 swf

I made an e learning app in flash and I use AS3 in this elearning, in this app, I call / load a eksternal swf what I make with AS2.
in that external swf, I have an input text for user, and when submit button clicked, I get the value of the input text and parse it to a global variable and then show it to a certificate.
Its working if I run the as2 swf independently, but if I load that as2 swf from the as3 swf, I can't getting value from the inputtext. its say undefined variable.
can anyone help / explain about my problem ?
thanks befor, sorry for my grammr. :)
AVM1 and AVM2 are incompatible this way. Therefore if you need to communicate between both, you have to use LocalConnection. This is the only option to establish communication between ActionScript 2 and ActionScript 3 movies.

addchild from externally loaded swf in Air project

I am working on an Air app for iOS and looking for a way to load an external swf and then add/remove the movieclips in that library to the main stage.
Normally, I can use an addchild routine in the document class of the external swf which I can access from the main document class. But since document classes in externally loaded swfs are not allowed in Air deployment, I can't use this method.
Each external swf will contain up to 10 separate movieclips and there are over 25 external swf's I want to load in/remove from the main stage, all containing unique artwork/animation.
Can anyone please suggest a way to do this?
THANKS!
matt
I had same problem i also had around 10 different external swfs with code. So the easiest way for me was to compile every file to swc and included them after in project.

Loading a SWF into an ActionScript 3 project (Flex Builder)

We're developing a small Flash gamelet for an European client of ours, who require us to develop our Flash game in such fashion that they can load our SWF game into their ActionScript 3 project, dynamically.
Basically they have a console that will load many other Flash games, amongst our own, depending on which button the player presses on a "Choose Your Game" screen.
Basically, we have a FLA project that we're authoring in Flash Professional CS4 and everything is basically a straightforward Flash game. When we test the game via Ctrl+Enter or run the compiled SWF file by double clicking it, all works well, the game executes perfectly and everybody is a happy bunny.
What we need to grasp is loading our SWF into our clients AS3 project, which is basically an external ActionScript 3 project created in Flex Builder 3. The client posted us the following code to load the SWF:
var myGame:FunkyChickenGame = new FunkyChickenGame();
addChild(myGame);
...which gets executed in the ActionScript 3 application constructor of the clients app, or perhaps an event handler for a button pressed on the "Choose Your Game" screen.
We tried creating a blank AS3 project in Flex Builder and tried loading the SWF as per my snippet above. All our traces within the external SWF's document class are showing up as expected in the Flex Builder console view, so the code is running perfectly.
The problem we're experiencing is that despite calling addChild(myGame)...we're not seeing any graphics, just the default background color of the encapsulating AS3 project.
Note however, when we run the SWF by double clicking the Game.swf file in Windows, it all executes perfectly, the game works without flaw and glitches.
Any help on this topic would be highly appreciated. Thank you in advance.
What you need to use is an instance of the Loader class, like so:
var loader:Loader = new Loader();
// you'll need to write a method named onLoaded to capture the COMPLETE event
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("game.swf"));
addChild(loader);
Creating an instance of a class is as wage as it can get. Your client has a funny way of posting references.
However FunkyChickenGame may be a class created by the client that can launch your game. Maybe the games are embedded in their flash app, but that would mean long loading time. If indeed many games are "loaded" this way.
My advice would be that you don't use stage, root or whatever properties that could link to the main app instead your game, and leave the client to decide how he would like to load it.