访问子movieClips FlashDevelop

时间:2010-02-17 02:03:12

标签: flex flash actionscript-3

我在另一个MovieClip中有一个movieClip。我给了孩子movieClip实例名称“hSprite”,并将其添加到父movieClip阶段。现在我收到如下错误。

[Fault] exception, information=ReferenceError: Error #1056: Cannot create property hSprite on com.objects.Hero.

如果我从子动画片段中删除实例名称,则错误消失。但是当我重新添加实例名称时,错误再次出现。

请记住,这两个类都设置为导出。

父类由一个完全正常的自定义类嵌入。但是,当我给孩子movieClip一个实例名称时,错误再次启动。

这是嵌入父类的类。我最初想要做的是访问Hero符号中的子MovieClip

package com.objects
{
   import flash.display.MovieClip;
   import flash.events.*;
   /**
    * ...
    * @author Anthony Gordon
    */
   [Embed(source='../../../bin/Assets.swf', symbol='Hero')]
   public class Hero extends GameObject
   {   
      private var aKeyPress:Array;
      private var jumpDisabled:Boolean = false;
      //private var heroSprite:MovieClip;

      public function Hero()
      {
         wY = 150;
         wX = 90;
         speed = .5;
         aKeyPress = new Array();
         TheGame.sr.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
         TheGame.sr.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
      }

      private function keyDownListener(e:KeyboardEvent):void {
          //trace("down e.keyCode=" + e.keyCode);         
          aKeyPress[e.keyCode]=true;
      }

      private function keyUpListener(e:KeyboardEvent):void {
         //trace("up e.keyCode=" + e.keyCode);
         aKeyPress[e.keyCode]=false;
      }

      override public function UpdateObject():void
      {
         Controls();
         updatePosition();
      }

      private function Controls():void
      {

         if (aKeyPress[38])//Key press up
            ;//dy -= speed;         
         else if (aKeyPress[40])//Key press down
            dy += speed;

         if (aKeyPress[37])//left
         {
            dx -= speed;
         }
         else if (aKeyPress[39])//Right
         {
            dx  += speed;
         }

         if (aKeyPress[32]){//space
            jump();
         }


      }//End Controls

      private function jump():void
      {
         if (!jumpDisabled)
         {
            if (onGround)
            {
               dy = -15;
               jumpDisabled = true;
            }
         }
         else
         {
            jumpDisabled = false;            
         }
      }
   }

}

1 个答案:

答案 0 :(得分:2)

您需要在类中将hSprite剪辑设为公共变量。

public var hSprite:MovieClip;