Event Handling For Toolbar Using Haxe Targeting Flash -


I am creating a simple UI toolbar component in hacks for use in a flash game. Toolbar is your normal UI style toolbar, its background and many buttons when buttons are clicked when there are some game actions.

I'm the best way to implement an event for toolbar buttons. A parent class will create a toolbar and then click the button on the click event, any action will sign up.

My current solution looks like this:

  • Toolbar
  • There is a child phantom for each button in the toolbar classroom.
  • Each button has an event listener for the mouse event. Click Event
  • A function on the MouseEvent toolbar is focused on examining a dynamic typed array of clicks and execution of each function contained in the array.
  • Dynamic type arrays are made public so that any classes that you want to sign up on the Toolbar button, click the event can add your callback function to the array.

The code snippet for a device that contains the toolbar

  this.toolbar = new ToolBar (); This.toolbar.OnAttackButtonClicked.push (OnAttackButtonClicked);  

Code snippet to create a button in the toolbar

  this.attackButton = new Sprite (); This.attackButton.addEventListener (MouseEvent.CLICK, this.OnAttackButtonClickListener);  

Code snippet for button click handler in the toolbar

  Private function OnAttackButtonClickListener (Event: MouseEvent): Zero {if (this.OnAttackButtonClallbacks! = Null) {Var Index: Int = this.OnAttackButtonCallbacks.length; Whereas (index -> gt; 0) {this.OnAttackButtonCallbacks [index] (event); }}}  

I am thinking that this is a good way or if there is a better way to do it?

solution. Used custom events and event dispatcher


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -