Sunday 25 April 2010

Video smoothing in AS3

This is an issue I found that has made serious difficulties to developers  about video playback. If you have a video file in flv format, and it has a size that is smaller than the stage where you want to show it in, Flash pixelizes the video. This is the default behaviour of Flash when playing video. 

There's a workaround but it's a direct one, as it was in AS2.

In AS2 you would do like this:

myVideoObject.smoothing = true | false

In AS3 you have to get to the "smoothing" in other way. Like this:
 
videoLoader.getVideoPlayer(videoLoader.activeVideoPlayerIndex).smoothing = true; 
 
 Where videoLoader is the FLVPlayback component that you insert with ActionScript.

Monday 12 April 2010

How to load an external SWF

This is how you can load an external SWF, using the progress event to make some sort of preloader.



import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;


function startLoad() {
   var mLoader:Loader = new Loader();
   var mRequest:URLRequest = new URLRequest(“MouseActions.swf”);
   mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteHandler);
   mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgressHandler);
   mLoader.load(mRequest);
}


function onCompleteHandler(loadEvent:Event) {
   addChild(loadEvent.currentTarget.content);
}


function onProgressHandler(mProgress:ProgressEvent) {
   var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
   trace(percent);
}

startLoad();