我在這裏有一個泡泡跳躍遊戲,泡泡從遊戲頂部落到底部,玩家嘗試在30秒內彈出儘可能多的泡泡。這是一個三幀遊戲,第一幀是開始按鈕,第二幀是遊戲,第三幀是比分,再次播放。 第一幀:進入第二幀的按鈕 第二幀:計時器對30秒的播放時間進行計數 第三幀:再次播放的按鈕。Actionscript 3.0:從AS3類訪問動態文本到遊戲
ScoreValue是遊戲最後一幀中的動態文本框。它根據泡泡大小的大小來記錄點數,並且應該根據玩家彈出泡泡的數量來改變。
scoreValue.text = score.toString();
Error 1120: Access of unidentified property scoreValue
無論如何,這裏的完整的代碼包。
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Sound;
import flash.geom.ColorTransform;
public class Ball extends MovieClip{
static public var burstCounter: uint;
private var vx: Number;
private var vy: Number;
private var gravity: Number;
private var stageWidth;
private var stageHeight;
private var bubble:Ball = new Ball();
private var score: uint=0;
public function Ball() {
bubble.addEventListener(Event.ADDED_TO_STAGE, initialize)
bubble.addEventListener(MouseEvent.CLICK, burst)
bubble.addEventListener(Event.ENTER_FRAME, dropping)
}
public function initialize (e:Event):void
{
bubble.x = Math.random() * stageWidth;
bubble.y = 0;
stageWidth = stage.stageWidth;
stageHeight = stage.stageHeight;
bubble.vx = Math.random() * 2 - 1;
bubble.vy = Math.random() * 2 + 1;
gravity = 0.1;
var sizeScale = Math.random() * 1.2 + .6;
bubble.scaleX = bubble.scaleY = sizeScale;
score = (10/sizeScale);
scoreValue.text = score.toString();
var colorTran = new ColorTransform();
colorTran.color = Math.random() * 0xFFFFFF;
transform.colorTransform = colorTran;
addChild(bubble);
}
function dropping(e: Event) :void
{
x += vx;
y += vy;
vy += gravity;
if((x<0) || (x>stageWidth) || (y<0) || (y>stageHeight))
{
if(parent != null)
{
parent.removeChild(this);
}
removeEventListener(Event.ENTER_FRAME, dropping)
}
}
function burst (e:Event):void
{
var ballonPopping: Sound = new BalloonPopping();
bubble.removeEventListener(Event.ADDED_TO_STAGE, initialize);
bubble.removeEventListener(Event.ENTER_FRAME, dropping);
removeChild(bubble);
ballonPopping.play();
burstCounter += score;
}
}
}
我得到這個作爲輸出在我的程序中,有沒有人知道爲什麼?
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
謝謝你的時間。
這通常只是一個警告,你有你的舞臺上,你選擇了一個非系統字體的動態文本框。你的問題到底是什麼?嘗試導入MouseEvent(如果這是你的錯誤):import flash.events.MouseEvent; – Randalfien 2012-04-04 16:41:07
**錯誤1120:訪問未識別的屬性scoreValue **意味着您在某個時刻缺少文本字段。請記住,在您調用其方法時,您拖到舞臺上的對象必須在舞臺上可用 - 稍後將它放在某個關鍵幀上也無濟於事。 – weltraumpirat 2012-04-04 17:04:56