How do I add an event to URLLoader Class? - actionscript-3

Keeping into consideration the Actionscript 3 event HTTPStatusEvent:HTTP_RESPONSE_STATUS, which is ONLY AVAILABLE for AIR (and not Flash 9/10)
Quote from site:
Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Lite 4
I would like to add the same EVENT by extending the HTTPStatusEvent Class of Actionscript 3 for Flash (9/10).
I'm working on Adobe Flash CS3 and I'm trying to get the "last" location of a URL loader (I'm calling a php with a header("Location: ..."); ) so I need the location after it changes. This should be made directly by flash and I cannot use php proxies not other.
Also, I cannot find the source code of the AIR HTTPStatusEvent Class, which I need to get the event (specifically, the responseHeaders and responseURL properties that the AIR class has).
Of course, if you know of any other way to accomplish this, feel free to share it.

You can't do it this way.
Think about it: You are trying to add behavior to the URLLoader class by extending an event class that is thrown from there. Figuratively speaking, it's a bit like changing the paper size when you've only written letters to your next door neighbor, and now you want them to go overseas - unless you also give them to the mail main, that's not going to be very successful...
I've stumbled across a number of forum threads discussing this, and most of them seem to agree that Adobe prevented access to response headers in Flash versions prior to FP10 / AIR due to some sort of security issue. I'm not sure how much of this information is accurate, but I am quite confident that there is no way to get around this - you can't get the Location:header in older Flash versions.
You will have to find some other workaround. For example, if you have access to the PHP script, you could add an HTML comment containing the redirect location, and parse that value in ActionScript.
<!-- Location: http://google.com/ -->

Related

How to set up MonsterDebugger and FlashDevelop?

I'm trying to follow directions given by MonsterDebugger I've linked the SWC, added the code. Then built the project.
The last thing they say: "Publish your project and watch the magic happen."
What I got is a SWF that is built to an http directory where my PHP file picks it up and displays it in browser.
What I'm expecting/want is to interact with my SWF application through browser and debug it with MonsterDebugger.
I'm obviously missing something since there it looks like there is no way for Monster tool to attach itself to the SWF? I'm not sure how does Monster will know about my published SWF?
I'm using FlashDevelop/FlashCS5 and Actionscript 3.
Sorry if this is a stupid question, but did you actually started Monster Debugger.exe after publishing and opening your project in browser? Also MonsterDebugger.initialize(); has second argument which is an address if you publishing and accessing your project on the server I suppose. Did you try to change it?
My bad. I had MonsterDebugger.initialize() statement to execute last in constructor of my document file. I moved initialize statement to be the very first line in my constructor. Now it attaches. Apparently there was some code that executed before initialize that caused issue. All is well now that it is the first line in the document file.

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)

Initialize function not fired in actionscript 3?

I'm trying to figure out the basics of an flash action script project. I downloaded a plugin (from Brightcove). As far as I can tell, it only has 2 relevant files.
BrightcovePlayerAPI.swc - the brightcove player api which you can import into your project
CaptionPlugin.as - just a small script that's supposed to load a dfxp.xml file.
I can't seem to get the function initialize() to fire in CaptionPlugin.as. I don't know what I'm doing wrong. Here's how I set up my project in Adobe Flash CS4:
start a flash actionscript 3 project
Save project as CaptionPlugin.fla
Go to properties panel and fill the class field with the word CaptionPlugin
Go to Publish Settings>Flash (tab)>settings>Library Path and included the BrightcoverPlayerAPI.swc as a line item
Saved all my changes
Went to Debug>Debug movie
I don't see my trace() statement inside the initialize() function fire at all? Can anyone suggest how i can debug this problem, or suggest what I might be doing wrong?
Ok, so this is the first time I've ever encountered Brightcove but I've had a quick look at their website and this is how it works. Brightcove is a service that allows you to customise and publish a cloud-based video player whilst the API you've downloaded only allows you to create custom modules or plugins to be integrated into this video player, see Creating Custom Player Components.
These components or custom modules are not intended to work as a stand-alone Flash file so the initialize() function won't be invoked when you run it alone. Once integrated with the video player and published correctly, the player will call initialize() when ready and your custom module will behave as you expect. See Getting Started with the Flash-Only Player for full details on how to publish the player.

Partial updates to an SWF

WHat is the standard method for say a server to update an already loaded SWF on the client browser, i.e. something analogous to how an html page is partially updated via ajax (though I don't know a lot about ajax yet either.) Would the mechanism be the same if user-initiated.
I assume the .SWF should have public functions that can be invoked, then you'll use javascript to access the swf from the html page its in, then invoke a public function of that swf.
Just the specific terms or functions I need to search for to get a primer on this would be great.
ALso, How would one go about testing the public functions of an swf that is already loaded in a browser (wihtout having a full Adobe devleopment suite for example).
This is quite a vast subject actually. This is the whole RIA concept. Flash can look after itself in terms of communicating with a server , you don't necessarily need Javascript. You only need a server side language to communicate with.
Since it all can happen within the swf , public functions don't really come into it. A User initiates an action in the movie that triggers a call to a remoting service which in turn sends a response which consequently updates the movie.
A few areas you can look into, in no particular order:
Flash PHP communication
Zend Amf Server ( Zend Framework )
http://framework.zend.com/
For testing purposes , try MonsterDebugger
http://gotoandlearn.com/play.php?id=109
Edit:
Flash can use PHP to retrieve a XML , then parse the XML & change the data inside the SWF according to the data retrieved in the XML
http://gotoandlearn.com/play.php?id=90
In case of a link, the concept is a bit different, because depending on the type of link this may cause a page refresh. The approach in the above tutorial could be user initiated by clicking on a swf element, entering text in a text input box etc... this is what I meant by the RIA concept. It's quite standard now in Flash that user interaction will introduce changes in your SWF by making calls to the server.

Can an AIR app be programmed to handle a URL protocol?

I'm writing what is essentially a browser in Adobe AIR (ActionScript, not AJAX). A great bit of functionality to implement would be protocol handling. iTunes, for instance, handles itms protocols; when your friend sends you a link beginning with "itms://", it's going to launch iTunes as long as it's installed. Is there a way to write an AIR app (requiring AIR 2 would be fine) that can be the "handler" for a protocol in this way?
There is no way, programatically speaking, to specifically handle a particular protocol. However, there is InvokeEvent. InvokeEvent will be fired when the application is "invoked", either when it's explictly launched or if an associated file or URL is activated.
The process of associating your app with a particular file type or protocol scheme is separate and application-dependant. In iOS, for example, you would need to specify the protocol in Info.plist under CFBundleURLTypes/CFBundleURLSchemes.
Yes. You can use the URLLoader class to download data in binary form (URLLoader.BINARY) and then parse this as appropriate. See this CS3 documentation on working with external data.
http://www.patrick-heinzelmann.de/labs/lastfm/
I'm not sure exactly how it works and I don't see a way to download the app, so I can't even test it, but maybe it will help...
Check out this page. I am trying to find out the same thing, but I haven't found any solution to do it with just Air yet. Seems like you might need a custom installer to setup the correct registry entries, and a proxy application to "wash" the input to a correct format that then can start your application with the correct command line parameters. Hope this can be of any assistance.