Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash hitTestObject(AS3)错误:访问未定义的属性_Flash - Fatal编程技术网

Flash hitTestObject(AS3)错误:访问未定义的属性

Flash hitTestObject(AS3)错误:访问未定义的属性,flash,Flash,在函数hitWall中,当玩家击中墙壁时,hitTestObject正在工作。我在舞台上有墙,叫做墙,墙2,墙3,墙4。使用同样的概念,我放置了其他电影唇(树),并将它们命名为:tree1、tree2等等 我收到一条错误消息:访问未定义的属性树 wall.addEventListener(Event.ENTER_FRAME, hitWall); tree.addEventListener(Event.ENTER_FRAME, hitTree); // function hitWall ----

在函数hitWall中,当玩家击中墙壁时,hitTestObject正在工作。我在舞台上有墙,叫做墙,墙2,墙3,墙4。使用同样的概念,我放置了其他电影唇(树),并将它们命名为:tree1、tree2等等

我收到一条错误消息:访问未定义的属性树

wall.addEventListener(Event.ENTER_FRAME, hitWall);
tree.addEventListener(Event.ENTER_FRAME, hitTree);

// function hitWall --------------------------------------------------------------
    function hitWall(event:Event):void {
        if (player_ary[me].hitTestObject(wall)) {
                player_ary[me].y+=6;
            } else if (player_ary[me].hitTestObject(wall2)) {
                player_ary[me].y-=6;

            } else if (player_ary[me].hitTestObject(wall3)) { 
                player_ary[me].x+=6;

            } else if (player_ary[me].hitTestObject(wall4)) {
                player_ary[me].x-=6;
            }

    }

    // function hitWall --------------------------------------------------------------
    function hitTree(event:Event):void {
        if (player_ary[me].hitTestObject(tree)) {
                player_ary[me].y+=6;
            } else if (player_ary[me].hitTestObject(tree2)) {
                player_ary[me].y-=6;
            } else if (player_ary[me].hitTestObject(tree3)) { 
                player_ary[me].x+=6;
                    }
     }

如果问题是我认为的那样

问题是当你有这样定义的类或函数

{
   var wall:Object = {name:"dodo"};
   wall.addEventListener(Event.ENTER_FRAME,doThis)
   function doThis(event:Event):void{
      trace (wall.name);
   }
}
墙实际上是空的。 整个函数在定义它的函数的上下文之外被调用

您需要做的是测试e.target(它将返回wall对象,因为您在其中添加了事件侦听器)或添加另一个事件侦听器,并使用类变量(即public var a:int)


这是一个常见的问题,人们从as2切换到as3,如果问题是我所认为的

问题是当你有这样定义的类或函数

{
   var wall:Object = {name:"dodo"};
   wall.addEventListener(Event.ENTER_FRAME,doThis)
   function doThis(event:Event):void{
      trace (wall.name);
   }
}
墙实际上是空的。 整个函数在定义它的函数的上下文之外被调用

您需要做的是测试e.target(它将返回wall对象,因为您在其中添加了事件侦听器)或添加另一个事件侦听器,并使用类变量(即public var a:int)


这是人们从as2切换到as3的常见问题。错误表明树MovieClip为空,因此问题不在代码的这一部分


如果树MovieClip是添加到stage的树的实例,请确保该实例存在,然后再对其调用方法。

错误表明树MovieClip为null,因此问题不在代码的这一部分

如果树MovieClip是添加到stage的树的实例,请确保该实例存在,然后再对其调用方法