Is there any way to handle new SWF loaded? - actionscript-3

i would like to know if there is a way to handle new SWF or class loaded in the AVM..
expecially in system domain.
What i was thinking to do is like call
ApplicationDomain.currentDomain.parentDomain.getQualifiedDefinitionNames();
every second and check for new classes(comparing last call result with new one). I don't like this way because it's a waste of performances and i prefer detect SWF instead of classes.
Hoping for some response, regards

Related

AS3 - replacing / taking over base AS function

I have following scenario:
I load many external swf files (they are at same domain) dynamically inside my AS3 loader.
All of them using navigateToURL (AS3) or getURL (AS2) on some buttons, that redirects to currently no more existing old domain.
Is it possible to replace (take over) navigateToURL and getURL base AS functions to change redirect link to up to date one or at least block loaded swf from opening urls?
No. You can extend classes, and implement your own override for methods/properties, but the previously compiled swf would need to point to your new class (which it won't).
You could try catching the error thrown (perhaps with UncaughtErrorEvent) and judiciously interpret the intended URL and dispatch the appropriate commands. The ideal would still be to just recompile the loaded SWF after running a search-and-replace for the deprecated method.

Using RequestURL to get to a different folder

I am using AS3 to make a game. I use RequestURL( filename ) to obtain the music I want to play. However, this means the music file has to be in the same folder as the .fla file. How can I use it to get a music file from a different folder? I don't really like having to leave my music outside of a Music folder or properly organised somehow....
EDIT: Should have mentioned this earlier. I tried to use simply something such as "whatever/filename", but I got this security error:
SecurityError: Error #2000: No active security context.
Why?
Have you tried using the flash.media.Sound.load() method yet?
//Make a new sound object
var s:Sound = new Sound();
//Load it
s.load(new URLRequest("someDifferentMusicFolder/loop.mp3"));
//Play it
s.play()
If you are loading it via another method, such as URLLoader + URLRequest, please post your code and we should be able to help a little better.
Generally speaking though URLRequests should allow you to specify different folders, so your problem may not be in the methodology you are using but may be in your implementation? Perhaps you are getting a security error? Whatever it may be, if you post your code we can help you narrow it down.

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)

Is it possible to access raw file data as FileReference.load() loads it in memory?

I think it's not, but maybe I'm wrong. Anyone?
UPDATE:
It's not.
i think you can, at least there is nothing in the docs that states otherwise. try adding a ProgressEvent on the FileReference object to read it's data (ByteArray) property after calling load().
however, if you're loading a file with URLLoader, a URLLoader's data property is only populated once the load operation has completed.
[EDIT]
so it's, after all, not possible to access live fileReference data while loading. the docs should explicitly state that it's not possible since it's a valid request.
however, after a some stumbling thru the docs i realized that you can do this by using the URLStream class, which provides methods to read data while it's loading - it's designed to do exactly what you are looking for.
the only catch, in this case, is that URLStream requires a full URL path (URLRequest object), which is not obtainable with FileReference for security reasons - it's only possible to get the name of a selected file, not the complete path. obtaining a local file path in AIR is very easy, but since you want your application to be browser-resistant i'm not quite sure how you'll be able to access file paths from the user's computer - unless they type in the file path, but requiring your users to do so would seriously degrade UX.
It is not possible currently...

How can I copy a NetStream Object?

I'm using BulkLoader to load an array of 10 or so FLV files. I want to be able to use and control these FLVs throughout my app independently. So for instance, FLV_1 may be displayed in duplicate but I want to pause one instance and play the other in tandem.
I would like to pass the NetStream object around to other Video objects and display both. Is this possible? If so, how do I go about doing it?
It's definitely possible. BulkLoader will expose you the NetStream object, so you can pass it around to Video or anything else, for example:
var videoItem : VideoItem = bulkLoader.get("my-video.flv");
var video : Video = new Video();
video.attachStream(videoItem.content);
// or the shortcut:
video.attachStream(bulkLoader.getNetStream("my-video.flv");
Regards
Haven't tested this but logically you shouldn't be able to play more than one video containing the same instance of a NetStream asynchronously, simply because the pause/play/etc. methods are triggered directly on the NetStream instance (and not on the Video containers...).
On the other hand you can probably play the same instance of a NetStream synchronously within different Video instances (to be double checked!).
Probably the easiest hack would be to load the same FLV into two different items (in case you use BulkLoader) referencing them with unique ID's and hoping the end-user has his browser cache enabled. Thereafter you would add and control each NetStream separately just as if you were handling two different movies.