Issue loading external swf on main file with as3 - actionscript-3

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

Related

How to load swf created with flipbook maker into flash

I'm trying to load the swf created by 'flip book maker' into my project.
the files created by flipbook maker are
book.swf
framework.swf
I used the following code
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("book.swf");
myLoader.load(url);
addChild(myLoader);``
the framework.swf is linked with book.swf, so it cannot run alone.
When I run the movie it shows the Error #2032, Stream error to framework.swf
book.swf and framework.swf both are in the same directory.They are generated by flip book maker What I needed is to load the book.swf into my project at a particular frame. I need help in AS3 for this purpose.
How to fix it..?
please help me..!
Error #2032 means that your Flash application could not load the framework.swf for some reason (you know this already of course). What you need to find out is why. Possible reasons are: you have the wrong URL, the framework.swf is not in the place you expect, there are crossdomain restrictions on the file you are trying to access ( you did not state where frameworks.swf).
What I would suggest doing is using a web debugging proxy tool like Fiddler (http://www.telerik.com/fiddler) or Firebug (is a Firefox extension) and take a look at the http requests to get more information on your error. You may find out that frameworks.swf is not in the location you expect.
This is just a IOError event triggered by Adobe Flash. Most likely the file just isn't found. Check your path and make sure you place the .swf file in your bin-debug directory if you're doing this from within Adobe Flash Builder

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

Can an actionScript2 app be used inside a AS3 app?

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

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.

Disable the error message box while loading an external movie with actionscript 3

I have a compiled swf file and a I can't edit it, but the movie is working fine (but gives an error message with a message box).
I am using it from an other movie (load with as3 code).
When the loader movie loads it the error message box appears.
I wonder is it possible to disable the errors while loading a movie with as3.
Here is the error in the message box:
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at motionsound11_fla::_all_29/motionsound11_fla::frame249()"
Yes. Here is the error message (editted my first post):
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at motionsound11_fla::_all_29/motionsound11_fla::frame249()"
And I don't want to decompile my movie. It becomes more complex when decompiled. Yes, for understanding the problem I did. But my first problem is disable the error message box.
Thanks so much.
Yes, You are right.
There is no error in a browser (with flash player plugin).
My project wont be in a browser. It will be an executable file (.exe) or .swf . So people who have "Adobe Flash CS3" on their computers will see the error in swf format file.
(i will add this information to my question : " The loader wont be on a web page. It will be used as .swf file or executable file" )
And your answer is acceptable. I will publish as html page not .exe or .swf. This will be more secure,dynamic and has no platform dependence.
Thanks.
I might be wrong here, but I'm not sure the release version of Flash player plugin would produce an error like that - are you running this in the debug plugin? What you could do is test on a box you know has never been used for development - it's possible the error simply won't appear when you deploy your application.
That said, any Flash developers who use your app might still see it!