flex游戏引擎(PushButton)--实体事件


// Example of dispatching an event from a component.
class TestComponent extends EntityComponent
{
   // Declare identifier for the event.
   static public const SOME_ACTION:String = "SomeAction";

   public function SomeActionHappens():void
   {
      owner.eventDispatcher.dispatchEvent(new Event(SOME_ACTION));

   }
}

// Example of listening for an event in a component.
class TestListenerComponent extends EntityComponent
{
   protected function onAdd():void
   {
      owner.eventDispatcher.addEventListener(TestComponent.SOME_ACTION, _EventHandler);
   }
  
   private function _EventHandler(e:Event):void
   {
      trace("Got an event!");
   }
  
   protected function onRemove():void
   {
      // Notice that we have to unsubscribe the event when the component
      // is removed.
      owner.eventDispatcher.removeEventListener(TestComponent.SOME_ACTION, _EventHandler);
   }
}

 

Entity表示实体

EntityComponent表示实体组件

实体组件的几个标准事件处理

class SimplerComponent extends EntityComponent
{

   protected override function onAdd():void
   {
      // Let superclass initialize, too.
      super.onAdd();
     
      // Initialize resources.
      // This will be called when the component is added to an entity.
   }

   protected override function onReset():void
   {
      // Let superclass reset, too.
      super.onReset();

      // (Re)acquire references to components inside the same entity.
      // This will be called after onAdd, whenever another component
      // is added or removed from the owning entity.
   }

   protected override function onRemove():void
   {
      // Let superclass remove, too.
      super.onRemove();

      // Release resources and references.
      // Called when the component is removed from its entity, usually
      // as part of the entity's destruction.
   }
  
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值