2014-02-18 31 views
0

有人能告诉我为什么会出现此错误吗?AS3- ReferenceError:Error#1069:Property not found

ReferenceError:错误#1069:未在com.usmanzubairi.theAges.TheAges上找到属性roll_mc并且没有默认值。 在com.usmanzubairi.theAges :: PirGame /滚动()

package com.usmanzubairi.theAges 
{ 
    import flash.display.MovieClip; 
    import flash.events.*; 
    import flash.media.*; 

public class TheAges extends MovieClip 
{ 
    private var game:PirGame; 
    private var game2:PreGame; 
    private var game3:SupGame; 


    public function TheAges() 
    { 
     stage.addEventListener(MouseEvent.CLICK, startGame); 
    } 


    private function startGame(event:Event):void 
    { 
     if (event.target != player_btn) 
     { 
       removeEventListener(MouseEvent.CLICK, startGame); 

       game = new PirGame(); 
       addChild(game); 
     } 

     else 
     { 
       addChild(player_mc); 
       player_mc.visible = true; 
       player_mc.play(); 
     } 

        if (event.target == player_mc.tom_mc) 
        { 
         removeEventListener(MouseEvent.CLICK, startGame); 

         game2 = new PreGame(); 
         addChild(game2); 
        } 

        if (event.target == player_mc.pete_mc) 
        { 
         removeEventListener(MouseEvent.CLICK, startGame); 

         game = new PirGame(); 
         addChild(game); 
        } 

        if(event.target == player_mc.sam_mc) 
        { 
         removeEventListener(MouseEvent.CLICK, startGame); 

         game3 = new SupGame(); 
         addChild(game3); 
        } 

    } 

    public function gameOver():void 
    { 
     removeChild(game); 
     game = null; 
     stage.addEventListener(MouseEvent.CLICK, startGame); 
    } 
} 

}

这里的PirGame文档类代码:

package com.usmanzubairi.theAges 
{ 
    import flash.utils.Timer; 
    import flash.events.*; 
    import flash.display.*; 
    import flash.geom.Matrix; 
    import flash.net.SharedObject; 

public class PirGame extends MovieClip 
{ 
    public function PirGame() 
    { 
     addEventListener(MouseEvent.CLICK,rolling); 
    } 

    private function rolling (event:Event):void 
    { 
     if (event.target == MovieClip(root).roll_mc) 
     { 
      addChild(roll) 
      roll.visible = true; 
      runner_mc.visible = false; 
      roll.play(); 
     } 

    } 

} 

}

感谢。

+0

你打算说一些关于“roll”的东西吗?你在roll()函数中使用的roll_mc是什么... –

+0

“roll”是一个滚动动画,“roll_mc”是播放该滚动动画的按钮。 – user3302134

+0

你确定roll_mc存在吗?尝试在你的条件之前测试它以查看值('if(MovieClip(root).roll_mc && event.target == MovieClip(root).roll_mc)')。如果为null,则该对象不存在。尝试调试你的电影(ctrl + maj + enter)而不是运行它(ctrl + enter),你会得到更好的错误信息,你可以看到所有的变量值都是错误时间。 –

回答

1

如果您roll_mc在你PirGame符号,我觉得Pirgame类是符号以及相关联的,尝试修改PirGame类如下:

package com.usmanzubairi.theAges 
{ 
    import flash.utils.Timer; 
    import flash.events.*; 
    import flash.display.*; 
    import flash.geom.Matrix; 
    import flash.net.SharedObject; 

    public class PirGame extends MovieClip 
    { 
     public function PirGame() 
     { 
      addEventListener(MouseEvent.CLICK,rolling); 
     } 

     private function rolling (event:Event):void 
     { 
      trace(event.target, roll_mc); 
      // change MovieClip(root).roll_mc to this.roll_mc as roll_mc is on this symbol and not on the root. 
      if(event.target == this.roll_mc) 
      { 
       trace('roll_mc clicked'); 
       addChild(roll) 
       roll.visible = true; 
       runner_mc.visible = false; 
       roll.play(); 
      } 
     } 
    } 
} 

,如果你只是想roll_mc可点击试试以下:

package com.usmanzubairi.theAges 
{ 
    import flash.utils.Timer; 
    import flash.events.*; 
    import flash.display.*; 
    import flash.geom.Matrix; 
    import flash.net.SharedObject; 

    public class PirGame extends MovieClip 
    { 
     public function PirGame() 
     { 
      if(roll_mc) roll_mc.addEventListener(MouseEvent.CLICK, rolling); 
      else   addEventListener(Event.ADDED_TO_STAGE, _onStage); 
     } 

     private function _onStage(e:Event):void 
     { 
      removeEventListener(Event.ADDED_TO_STAGE, _onStage); 
      roll_mc.addEventListener(MouseEvent.CLICK, rolling); 
     } 

     private function rolling(e:Event):void 
     { 
      trace('roll_mc clicked'); 
      addChild(roll) 
      roll.visible = true; 
      runner_mc.visible = false; 
      roll.play(); 
     } 
    } 
} 

如果你没有重新显示runner_mc你可以从显示列表中删除它,而不是让它不可见:

removeChild(runner_mc); 
+0

感谢您的回复。我使用了你发给我的代码。但是,尽管我没有错误,但动画仍然卡住,并继续运行动画。这很奇怪,因为我之前看到动画工作正常,之前我的** ReferenceError:错误#1069:** – user3302134

+0

尝试添加跟踪我编辑过的代码 –

+0

您是否还有其他物体可以在滚动中被点击和检测功能?如果没有,您可以添加mouseEvent直接在roll_mc上单击侦听器,那更好。 –