5.外部画像の読み込み2
ちょっと修正
試行錯誤の末、以下のようにすればとりあえず意図通りに動いてくれました。他にスマートなのがあれば教えて下さい。<(_ _)>
//test.as 画像読み込みテスト2
package {
import flash.display.*;
import flash.events.*;//★
public class test extends Sprite {//クラス宣言
[Embed(source='testimg.jpg')]
private static const ImageEx:Class;
private var bmp:Bitmap;//■
public function test(){//コンストラクタ
//■var bmp:Bitmap = new ImageEx() as Bitmap;
bmp = new ImageEx() as Bitmap;//■
addChild(bmp);
addEventListener(Event.ENTER_FRAME, enterframe);//★
}
private function enterframe(event:Event):void {//★
bmp.x+=1;
}
}
}
package {
import flash.display.*;
import flash.events.*;//★
public class test extends Sprite {//クラス宣言
[Embed(source='testimg.jpg')]
private static const ImageEx:Class;
private var bmp:Bitmap;//■
public function test(){//コンストラクタ
//■var bmp:Bitmap = new ImageEx() as Bitmap;
bmp = new ImageEx() as Bitmap;//■
addChild(bmp);
addEventListener(Event.ENTER_FRAME, enterframe);//★
}
private function enterframe(event:Event):void {//★
bmp.x+=1;
}
}
}
■部分が変更した部分。★はコンストラクタ以外のところからbmpオブジェクトを動かすために追加した部分。
最初のスクリプトでこのように別なところから動かそうとすると、bmpってなんじゃい?ってコンパイル時に怒られますが、これだとOK。