加載bitmapData時出現問題。我收到以下錯誤ArgumentError:錯誤#2015:無效的BitmapData
Engine Init //trace
loadimage//trace
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
下面是我的代碼。它出現在跟蹤的LoadImage
package com.objects {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.*;
import flash.events.*;
import flash.display.LoaderInfo;
public class gameObject extends Sprite {
protected var w:Number;
protected var h:Number;
protected var image:BitmapData;
protected var canvas:Bitmap;
protected var px:Number;
protected var py:Number;
public function gameObject():void
{
init();
}
private function init():void
{
}
public function loadImage(imageDir:String, w:Number, h:Number, px:Number, py:Number):void
{
this.w = w;
this.y = y;
this.px = px;
this.py = py;
trace("loadimage");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageComplete);
loader.load(new URLRequest(imageDir));
}
private function imageComplete(e:Event):void {
var loader:LoaderInfo = LoaderInfo(e.target);
image = Bitmap(loader.content).bitmapData;
drawImage();
}
private function drawImage():void
{
var tilePoint:Point = new Point(0,0);
var tileRect = new Rectangle(py,px,w,h);
trace(loader.content);
var canvasData:BitmapData = new BitmapData(w,h);
trace("got canvas data");
canvasData.copyPixels(image,tileRect,tilePoint);
trace("copied pixels");
canvas = new Bitmap(canvasData);
}
}
}
後正好與我通話的方法是像這樣
balls = new Array();
balls[0] = new gameObject();
balls[0].loadImage("com/images/ball.gif", 15,15,0,0);
當我跟蹤Loader.content,下面就是顯示
Engine Init
loadimage
[object Bitmap]
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
我想,和它說我不能將LoaderInfo轉換爲Loader(),所以當我跟蹤loader.content時,LoaderInfo也是正確的,我得到了 ... [對象位圖],這意味着位圖對象在其中。 – numerical25 2010-01-09 17:20:11
奇怪的是,它工作正常,如果我硬編碼canvasData的寬度和高度。但如果我使用varibles,它並不 – numerical25 2010-01-10 03:24:58