Reverse Video Playback
If you’re at all familiar with video within flash you’ll know that there is no built in functionality to play a video in reverse. The reason for this is quite simple. When a video is encoded regardless of the codec or the wrapper format some frames are keyframes (iFrames) and other are in-between frames (pFrames or bFrames). Basically the in-between frames need data from other frames, which are usually sequentially before them, so if the video is played in reverse each time an in-between frame is encountered data will potentially be missing.
You could make every frame a key-frame to get around this, however this would result in huge file size.
Another approach that can work in some cases is to take a bitmapdata capture of each frame as the video plays, save them to a Vector and then once this process has been completed you can jump to any frame within the Vector regardless of if the original frame was a key-frame or not, or even play through the Vector in reverse.
The movie above demonstrate this method, source files can be download from here.
The downside to this approach is that each frame that is placed in the Vector has to be saved into memory, so if the video is really long in length, or has large dimensions this may slow performance significantly, so keep this in mind. The other downside is that you have to play through the video to capture each frame before you can play it in reverse, I guess it really depends on your project as to if this is going to be an issue.
The above example is lacking buffer checking, so if the video starts buffering half way through playback the reverse sequence will capture this. This could be fixed pretty easily by putting in an “if buffering don’t capture” statement, but I don’t really need it for what I’m doing. For a more solid solution you’d also probably want to use a timer rather than enter frame.
Read MoreFirst Person Interaction For Flash Please!
Update: This feature has now been added to flash 11.2. you can read more about it here: http://www.bytearray.org/?p=3755
———————————————————————————————————-
———————————————————————————————————-
While creating 3d environments within flash you are currently limited in the way you get user mouse input. In your traditional first person shooters moving the mouse will turn the view left and right, up and down. The problem you face within flash is that once the mouse hits the edge of the movie or if it is in full-screen mode, the side of the screen there is no way to receive mouse input as the mouseX and mouseY values to longer change, even if the user is still moving the mouse.
The first two videos below show methods which are achievable with the current functionality, the last video shows what would be possible if we had access to raw mouseOffset values.
AbsoluteDrag shows the view turning via the absolute location of the mouse. The problem with this method is that as soon as the cursor hits the side of the flash movie input stops.
AbsoluteClickAndDrag only turns the view when the user clicks and drags the mouse. This method continues to turn the view after the cursor has left the stage as long as the mouse button remains held down, however stops as soon as the cursor hits the side of the screen, it’s also not ideal for the user to always have to click and drag to turn as you would usually use the left mouse button as an action input (eg fire your gun).
RelativeDrag is my suggestion to this problem. With this extra functionality you could turn the view based on the raw mouse offset values, this way it doesn’t matter if the mouse is outside the flash movie or is even hard up against the side of the screen, the view will continue to turn. In the above example video this was achieved by opening a socket to a small c based program which broadcasts the mouse x and y offsets, however obviously you don’t want the user to have to download an extra program every time you use this kind of interaction.
Possible solutions:
1. Two new mouse properties: mouseOffsetX and mosueOffsetY, which would give you the displacement of the raw mouse data in the X and Y. These properties would output the raw offsets regardless of if the mouse was against one side of the screen or outside the stage.
2. Another option would be to make the mouseX and mouseY properties read/write. I realize there are potential security issues surrounding this approach as I am sure malicious sites would steal the users cursor, however if this was only available in full-screen mode or the user was prompted with a message similar to the microphone access message this approach could work.
The flash player team must be extremely busy with other issues, however this would be a really helpful addition to the player that would really open up the possibilities for 3d gaming environments.
If you think this added functionality a good idea and would like to support the request please visit the below url and cast your vote.
http://bugs.adobe.com/jira/browse/FP-4523
Cheers
Read MoreTextToSpeech Accessibility
I recently posted a TextToSpeech as3 interface class which you can view here. Basically you pass it a string and it will read it out loud.
Today I’ve added an easy way to increase the accessibility of your flash microsite without having to go through the whole project adding code to every button. Simply add the two lines below to your root document and this class will search through every display object and add rollover text to speech.
1 2 3 | import ps.GText2Speech.Accessibility; var accessibility:Accessibility = new Accessibility(this); |
You can also specify to read the text on a click or rollout instead of the default rollover.
1 2 3 4 5 6 | import ps.GText2Speech.Accessibility; var accessibility:Accessibility = new Accessibility(this); accessibility.Rollover = false; accessibility.Click = true; accessibility.Rollout = true; |
In most cases there will probably be some textfields you want to ignore, so if you need to do this simply add the display object to the exclude list.
1 | accessibility.exclude(mc_skip); |
You can download the source and example files here.
If you fine any bugs or have any additional feature requests please post them below.
Enjoy!
Actionscript Text To Speech
Ever wanted to add text to speech functionality to your Actionscript project?
Well now you can thanks to this cool little as3 class I wrote last night.
So how does it work?
Google hasn’t released an official API for their text to speech engine, however if you query: http://translate.google.com/translate_tts?tl=en&q=this%20is%20a%20test an mp3 will be produced which speaks whatever q equals. There is however a limit to how many characters will be accepted in one query. TextToSpeech.as gets around this limitation by splitting your request up into smaller more manageable parts and then requests them one at a time. TextToSpeech.as also fixes the delay between clips on playback by starting playback of the next segment just before the current one finishes.
TextToSpeech.as simply bridges the gap between the Google text to speech engine and your as3 project. The example below imports TextToSpeech.as, loads a string (the first paragraph of this blog) and then plays it once the first segment has been converted and downloaded.
1 2 3 4 5 6 7 8 9 10 11 12 | import ps.GText2Speech.TextToSpeech; import ps.GTranslate.Language; textToSpeech = new TextToSpeech(); textToSpeech.Lang = Language.ENGLISH; textToSpeech.addEventListener("FirstClipLoaded", beginPlaying); textToSpeech.load('Ever wanted to add text to speech functionality to your Actionscript project? Well now you can thanks to Google and this awesome little as3 class I’ve written.'); function beginPlaying(event:Event):void { textToSpeech.play(); } |
Because TextToSpeech.as relies on the Google TextToSpeech engine it does mean that this could stop working in the future if Google decides to change or remove the URL. I guess the best way would be to actually do everything within actionscript, however this is easier said than done, so for the time being this is the best option we have.
You can download the source and example files here.
If anyone has additional feature requests please post them below.
Enjoy!
——————————————————
Update – Leading on from this post I’ve added a TextToSpeech accessibility class: Read More
——————————————————
Update – Seems to be a problem with the request within IE, not to sure what the problem is as I’m on a mac. I guess if you want to use this for a project it’d probably be a good idea to use a proxy on the same domain as your flash content.

Recent Comments