Actionscript: Check Throttle Status? - actionscript-3

Is there a way to check the throttle status without using ThrottleEvent?
E.g., someone else's Flash container swf loads, gets throttled and receives the ThrottleEvent, then loads my swf. Can my swf tell that it's throttled?
(Assume I do not know the owner of the container swf and cannot change it in any way.)

Related

NetStream.publish() to AMS ends up with 1kb file

I'm using Adobe Media Server 4.5 and the FLEX 4.6.0 sdk.
I have an .swf application that connects to Adobe Media Server over RMTP, takes audio and video input from the user's webcam and mic, and does a NetStream.publish() to stream the file to the server. The file grows in size as the user records the video. On occasion, the resulting file will end up with a size of 1kb.
What's causing this and how can I prevent it, or otherwise end the session and inform the user that something went wrong?
Edit:
Some additional questions/comments/opinions that might help identify the problem:
This only happens 1% of the time, and I'm not sure what I can use to troubleshoot this. I've never been able to catch when this happens before the log files generated by AMS expire.
My theory is that it happens when the client loses connection somewhere.
As long as the NetStream is publishing correctly, the file will grow in size.
If the file doesn't grow, it should mean that the NetStream lost connection. Seeing as the file is 1kb, the stream must have lost connection immediately after starting to publish.
I also opened the file in Notepad++ and got this:
FLV [SOH][NUL][NUL][NUL][NUL] [NUL][NUL][NUL][NUL]
Another theory is that something has a chance to overwrite my file, but this is unlikely
Have the same problem, but 0.001% of the cases.
The most common problem occurs because of a microphone.
Need to check the microphone before publishing a stream.
Another possible problem:
Client interrupts the flow - NetStream.Record.Stop
Exits the application - onDisconnect
Сlient disables the microphone / camera
"The FLV segment cache is full"
Can warn if called onUnpublish event on the server.
I also use the timer after the publish () method on the client side, if after 3-5 seconds NetStream.Record.Start event is not called, then the client has a problem and it should be prevented.

How to get Flex SWFLoader unloadAndStop to unload sound also?

public var swfLoader:SWFLoader = new SWFLoader();
[Embed(source="/some/file1.swf")]
public var file1:Class;
[Embed(source="/some/file2.swf")]
public var file2:Class;
then I do:
swfLoader.load(file1);
Later on:
swfLoader.unloadAndStop(true);
which unloads the video, but not the sound! So I add in
SoundMixer.stopAll();
Which is ok, for a while. Later on, I do:
swfLoader.load(file2);
And eventually, while watching file2, file1's audio will start playing in the background over file2's audio, with no way to stop it! What is the proper way to stop the audio of file1? The way I keep seeing is use unloadAndStop() which I am using. Unless I have to create a new swfLoader object each time?
As per Konrad's answer below, I should stop playing the sound in cleanup events, such as REMOVED_FROM_STAGE, however, how can I stop playing the sound on a swf file that is loaded with a SWFLoader? I don't see an obvious way to do that.
Solutions is bit tricky, because problem is with loaded content.
Garbage collector won't remove sound because it is still playing (so its referenced by Flash Player) but you don't have access to its sound channel (because its hidden similar to private variables in classes). That behavior is totally correct.
Solution: In loaded swf code you should stop playing that sound (in REMOVED_FROM_STAGE or other 'cleanup' event handler). Other solutions (like SoundMixer.stopAll) will work in some cases but not in all.
We often forget to clean after ours applications. Its not problem if they exist same as instance of Flash Player (removing it will clean all memory used by our swf). Problems begins when we load and unload swfs. Ignoring cleanups is fast way to memory leaks.
swfLoader.unloadAndStop(true);
Does remove the swf and the sound as well .
Works fine for me .
Even the documentation says :
Unloads an image or SWF file. After this method returns the source property will be null. This is only supported if the host Flash Player is version 10 or greater. If the host Flash Player is less than version 10, then this method will unload the content the same way as if source was set to null. This method attempts to unload SWF files by removing references to EventDispatcher, NetConnection, Timer, Sound, or Video objects of the child SWF file. As a result, the following occurs for the child SWF file and the child SWF file's display list:
Sounds are stopped.
Stage event listeners are removed.
Event listeners for enterFrame, frameConstructed, exitFrame, activate and deactivate are removed.
Timers are stopped.
Camera and Microphone instances are detached
Movie clips are stopped.

Why does my second loaded subapp stop after FlexEvent.INITIALIZE

I have a Flex 4 application that loads Flex 4 applications into it by using the mx.controls.SWFLoader component. I load the same swf-subapp several times as each subapp also runs standalone, and the content of the subapp is determined by a XML that I pass into it via the loader context.
This has worked until recently, but now, the second time I load the same swf (with a different xml) the loaded swf stops executing anything after the FlexEvent.INITIALIZE is triggered (I'm not doing anything in my initialized event handler). In other words, I don't get a CreationComplete event, which is where I start my code (and worse, no errors either).
As I've been working on a different part of my main application, I can't quite remember which change crashed my project, but what I do remember is that I updated my Flex SDK and I've hade similar silent errors in relation to a SDK upgrade earlier.
In my main application I do cleanup after myself before loading a new swf, so it shouldn't be garbage laying around.
Please help!
Solved it.
There was an enterframe handler that kept the first instance of the swf in memory, that in some way blocked the next one from loading (eventhough I used the removeAllElements on the parent container and hoped that would do the trick).
Now I use a NativeSignal and remove all listeners from that on onRemove handler (RobotLegs). Works like a charm.

FLVPlayback clip loading delays

I'm building a narrative click-through kiosk app in Flash/AS3. Currently, there are several (10+) locally loaded .flv files that I'm loading into an FLVPlayback component on the timeline. I am experiencing loading delays and am wondering what the best practice / best case scenario for this case. These are all using the "Load external video with playback component" option for Video importing.
So far I've tried implementing it two ways:
One frame, one FLVPlayback playback on the stage named "video_player", and upon the click through / user action to switch the video, I do the following:
var new_flv:String = "next_flv.flv";
video_player.stop();
video_player.source("_flvs/"+new_flv);
video_player.seek(0);
video_player.play();
This results in delays anywhere from a few seconds to 10 seconds.
This is unconventional to me, but I used multiple frames on the timeline. Each frame had an FLVPlayback instance on the stage, each with a different relative path placed in the 'source' property in the component parameters (see http://www.ashleylovespizza.org/stuff/flv_example.png ). The code is switching between frames based on frame label and then hitting play (autoplay is off in the component parameters as well).
var new_flv_frame_name:String = "next_frame";
this.gotoAndStop(new_flv_frame_name);
this.video_player.play();
The issue, again, is that loading is taking a long time. What could prevent this behavior? One long flv that I seek() to different moments of time on the playhead? Can I preload in a separate FLVPlayback instance, similar to double buffering?
Any tips or best practices are appreciated.
Although you have not told me where the flv files are being loaded from (locally or remote), and as you have said you are building a kiosk style app, I am going to go out on a limb here and say that you should almost certainly use Adobe AIR for a kiosk app.
There is no reason for creating more than one FLVPlayback instance, its capable of playing multiple videos using getVideoPlayer(index), its up to you to manage the streams by calling close() on them.
If you are loading files remotely, then using Adobe AIR you can download each video to a local folder using the FileStream class. This will speed up the process of playing back these files.

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)