Fix for Error #1063: Argument count mismatch on BitmapData Expected 2, got 0.
Normally creating blank BitmapData requires you pass in an the width and height in pixels. But what about when you embed an image with a linkageid? You'll get the above error trying to create a new myEmbeddedImage(); unless you pass it with two numbers, even if they don't mean anything e.g.
var bdata:BitmapData = new imageInLibraryLinkageID(0,0);
I would have thought that these would be optional for embedded assets. Fix originally discovered here.
AS3: Reloading Images? Fix for Error #2025: The supplied DisplayObject must be a child of the caller.
I have an image rotator that reloads images into the same clip. This took me a bit to figure out. I'm using the non-visible preloader technique earlier in the blog, but it's modified to not throw errors via calling loader.unload() prior to adding the content to the target clip, apparently there is some contention over who owns it. Here's the code.
dynamic public class IMGLoader extends MovieClip {
private var images:Array = ["focused.JPG","TroyWorks-80x80.jpg"];
protected var _loader:Loader;
public var loading_mc:MovieClip;
public var reload_mc:MovieClip;
public var lt_mc:MovieClip;
public var curClip:DisplayObject;public function IMGLoader() {
super();
trace("IMGLOader " + reload_mc);
/////////////////////////////////////
_loader = new Loader();
configureListeners(_loader.contentLoaderInfo);
reload_mc.addEventListener(MouseEvent.CLICK, startLoad);
startLoad();}
public function getNextImageURL():String{
var curURL:String = images.shift();
images.push(curURL);
return curURL;
}
public function startLoad(evt:Event = null):void{///////////// show loading animation ///////////
loading_mc.visible=true;
loading_mc.play();
var url:String = getNextImageURL();
trace("startLoadofImage" + url);
var request:URLRequest = new URLRequest(url);
//var clip:DisplayObject = lt_mc.getChild(curClip);_loader.load(request);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(Event.INIT, initHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
}private function completeHandler(event:Event):void {
trace("completeHandler: " + event);
var clip:DisplayObject = DisplayObject(LoaderInfo(event.target).content);
clip.width = lt_mc.width;
clip.height = lt_mc.height;
trace("clip.name " + clip.name);
_loader.unload();
if(lt_mc.numChildren >1 ){
//lt_mc.removeChild(clip);
lt_mc.removeChildAt(1);
}
lt_mc.addChildAt(clip, 1);
curClip = clip;
trace("clip Loaded at " + lt_mc.getChildIndex(curClip));
///////////// hide loading animation ///////////
loading_mc.visible=false;
loading_mc.stop();
}
