0
我試圖學習ActionScript 3作爲我的第一種編程語言(在此之前,我只在過去一些小小的廢話與PHP)。錯誤:在AS3中訪問未定義的屬性
我有這樣的代碼:
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
/**
* ...
* @author Mattia Del Franco
*/
[Frame(factoryClass="Preloader")]
public class Main extends Sprite
{
[Embed(source = "img/pgnew.png")]
internal var MyImage:Class;
// La riga embed importa l'immagine, la riga sotto la assegna ad una classe chiamata MyImage
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
trace ("Hello World!");
var myBitmap:Bitmap = new MyImage; //nuova variabile myBitmap al quale viene assegnato la creazione di un nuovo MyImage (trattato come un oggetto)
addChild(myBitmap);
var writeText:TextField = new TextField();
writeText.text = "Ciao Mondo!";
this.addEventListener(MouseEvent.CLICK, function(){
addChild(writeText);
var clicked:Boolean = true;
return clicked;
});
this.addEventListener(MouseEvent.CLICK, function() {
if (clicked == true) {
removeChild(writeText);
} else {
addChild(writeText);
}
});
}
}
}
在第二個事件監聽我想獲得的布爾值點擊(在第一個事件監聽指定的),但是當我去調試這個節目,我得到這個錯誤:
col:9錯誤:單擊未定義屬性的訪問權限。 if(clicked == true){
爲什麼會發生這種情況?
@Mattia如果我的回答是分辯你能接受 – 2014-10-12 12:07:27