我無法解決這個錯誤,當我這樣做會導致另一個。我希望能夠擊中關鍵「71」,並將新的movieclip實例添加到舞臺上。有什麼建議麼?我是個新手,所以可能很多錯誤......第108行t 1136:參數數量不正確。預計1
包{
import flash.display.MovieClip; //imports needed
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.text.engine.EastAsianJustifier;
import flash.events.KeyboardEvent;
import flash.display.Stage;
public class myJellyFish extends MovieClip {
private var startScaleX:Number;
private var startScaleY:Number;
//private var cliqued:Number;
private var stayonscreenLeft:Number;
private var stayonscreenRight:Number;
private var stayonscreenTop:Number;
private var stayonscreenBottom:Number;
private var moveDirection:Number;
private var speed:Number;
private var turnspeed:Number;
public function myJellyFish() {
startScaleX = this.scaleX;
startScaleY = this.scaleY;
stayonscreenBottom = 400;
stayonscreenRight = 500;
stayonscreenLeft = 5;
stayonscreenTop = 5;
moveDirection = .5;
speed = Math.random()*10;
turnspeed = 25;
this.addEventListener(MouseEvent.ROLL_OVER, scrolledOver);
this.addEventListener(MouseEvent.ROLL_OUT, scrolledOff);
this.addEventListener(MouseEvent.CLICK, directionChange);
this.addEventListener(Event.ENTER_FRAME, life)
trace("custom class be a working");
// constructor code
}
function myMethod() {
trace("method also be a workin'");
}
private function scrolledOver(Event:MouseEvent):void{
this.alpha = .5;
}
private function scrolledOff(Event:MouseEvent):void{
this.alpha = 1;
}
private function directionChange(e:Event):void{
moveDirection = moveDirection * -1;
}
private function life(e:Event):void{
if (moveDirection > 0){
Hmovement();
}
if (moveDirection < 0){
Vmovement();
}
}
private function Vmovement():void{
this.y += speed;
if(this.y <= stayonscreenBottom){
speed = speed * -1;
this.startScaleY * -1;
}
if(this.y >= stayonscreenTop){
speed = speed * -1;
this.startScaleY * -1;
}
}
private function Hmovement():void{
this.x += speed;
if(this.x >= stayonscreenRight){
speed = speed * -1;
}
if(this.x <= stayonscreenLeft){
speed = speed * -1;
}
}
private function generate(e:KeyboardEvent):void{
var movieClip:myJellyFish = new myJellyFish();
addChild(movieClip);
movieClip.x = (Math.random() * 200) + 20;
movieClip.y = (Math.random()*200) + 20;
movieClip.name = "jellyfish";
}
public function moreClips (event:KeyboardEvent){ //if that key is "F" it will play the tween
trace(event.keyCode);
if (event.keyCode == 71){
generate();
}
}
}//end class
}//end package
即時通過:場景1,圖層'操作',幀361,7行\t 1120:訪問未定義的屬性moreClips。現在,如果我加入舞臺的東西,我得到:第54行\t 1119:訪問可能未定義的屬性addedToStage通過靜態類型的引用類。 –
@ user3200134我刪除了'Event.ADDED_TO_STAGE'事件(被Event.addedToStage')修復了一個錯字。這應該解決你的第二個問題。 **對於你的第一個問題; **我寫的代碼應該添加到你上面發佈的同一個類中。因此,應該將事件偵聽器添加到構造函數的其餘代碼中,並且應該將handleAddedToStage函數添加到類中。從錯誤,它看起來好像你已經添加我的代碼在一個框架中... –