2012-04-04 65 views
0

我在这里有一个泡泡跳跃游戏,泡泡从游戏顶部落到底部,玩家尝试在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. 

谢谢你的时间。

+1

这通常只是一个警告,你有你的舞台上,你选择了一个非系统字体的动态文本框。你的问题到底是什么?尝试导入MouseEvent(如果这是你的错误):import flash.events.MouseEvent; – Randalfien 2012-04-04 16:41:07

+0

**错误1120:访问未识别的属性scoreValue **意味着您在某个时刻缺少文本字段。请记住,在您调用其方法时,您拖到舞台上的对象必须在舞台上可用 - 稍后将它放在某个关键帧上也无济于事。 – weltraumpirat 2012-04-04 17:04:56

回答

0

首先,在一个类中,函数应定义为publicprivate。其次,当您为其分配MouseEvent时,您的burst函数期待Event。这是我常用的一个简单的错误。

将其更改为:

private function burst (e:MouseEvent):void 

输出面板字体件事意味着你有一个动态文本字段的地方。只要到您的FLA,开启一个文本框,并在属性面板中,点击嵌入按钮并选择基本拉丁语复选框...或数字,如果它只是数字

编辑:也改变你的进口

import flash.events.*; 

或添加

import flash.events.MouseEvent; 
+2

FYI MouseEvent继承事件。因此,只要他不试图访问任何MouseEvent属性,就可以使用Event作为回调函数突发的参数。 – 2012-04-04 16:51:26

+0

是的,你是对的,但最好的做法是不是要走的路。 – Ronnie 2012-04-04 16:55:14

+2

@罗尼这不是一个错误,我希望看到最好的写作实践。另外,你可以将方法声明为'protected'或'internal'。 – weltraumpirat 2012-04-04 17:02:18

1

需要导入MouseEvent类来解决

了“的访问的MouseEvent未定义的属性”添加到您的导入状态ments:

import flash.events.MouseEvent;