Skip to main content
Inspiring
May 16, 2016
Question

1090: Migration issue: The onMouseUp event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseUp', callback_handler).

  • May 16, 2016
  • 1 reply
  • 469 views

1090: Migration issue: The onMouseUp event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseUp', callback_handler)

i just added 

addEventListener ( 'mouseUp', callback_handler) this line in the code  but then it shows  "Call to a possibly undefined method addEventListener."

so my question is how can i add  this code in the program  : addEventListener ( 'mouseUp', callback_handler);

the complete code is

package com.bit101.components

{

  import flash.display.DisplayObjectContainer;

  import flash.display.Sprite;

  import flash.events.MouseEvent;

  public class PushButton extends Component

  {

  protected var _back:Sprite;

  protected var _face:Sprite;

  protected var _label:Label;

  protected var _labelText:String = "";

  protected var _over:Boolean = false;

  protected var _down:Boolean = false;

  protected var _selected:Boolean = false;

  protected var _toggle:Boolean = false;

  /**

  * Constructor

  * @9397041 parent The parent DisplayObjectContainer on which to add this PushButton.

  * @9397041 xpos The x position to place this component.

  * @9397041 ypos The y position to place this component.

  * @9397041 label The string to use for the initial label of this component.

  * @9397041 defaultHandler The event handling function to handle the default event for this component (click in this case).

  */

  public function PushButton(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number =  0, label:String = "", defaultHandler:Function = null)

  {

  super(parent, xpos, ypos);

  if(defaultHandler != null)

  {

  addEventListener(MouseEvent.CLICK, defaultHandler);

  }

  this.label = label;

  }

  /**

  * Initializes the component.

  */

  override protected function init():void

  {

  super.init();

  buttonMode = true;

  useHandCursor = true;

  setSize(100, 20);

  }

  /**

  * Creates and adds the child display objects of this component.

  */

  override protected function addChildren():void

  {

  _back = new Sprite();

  _back.filters = [getShadow(2, true)];

  _back.mouseEnabled = false;

  addChild(_back);

  _face = new Sprite();

  _face.mouseEnabled = false;

  _face.filters = [getShadow(1)];

  _face.x = 1;

  _face.y = 1;

  addChild(_face);

  _label = new Label();

  addChild(_label);

  addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);

  addEventListener(MouseEvent.ROLL_OVER, onMouseOver);

  }

  ///////////////////////////////////

  // public methods

  ///////////////////////////////////

  /**

  * Draws the visual ui of the component.

  */

  override public function draw():void

  {

  super.draw();

  _back.graphics.clear();

  _back.graphics.beginFill(Style.BACKGROUND);

  _back.graphics.drawRect(0, 0, _width, _height);

  _back.graphics.endFill();

  _face.graphics.clear();

  _face.graphics.beginFill(Style.BUTTON_FACE);

  _face.graphics.drawRect(0, 0, _width - 2, _height - 2);

  _face.graphics.endFill();

  _label.autoSize = true;

  _label.text = _labelText;

  if(_label.width > _width - 4)

  {

  _label.autoSize = false;

  _label.width = _width - 4;

  }

  else

  {

  _label.autoSize = true;

  }

  _label.draw();

  _label.move(_width / 2 - _label.width / 2, _height / 2 - _label.height / 2);

  }

  ///////////////////////////////////

  // event handlers

  ///////////////////////////////////

  /**

  * Internal mouseOver handler.

  * @9397041 event The MouseEvent passed by the system.

  */

  protected function onMouseOver(event:MouseEvent):void

  {

  _over = true;

  addEventListener(MouseEvent.ROLL_OUT, onMouseOut);

  }

  /**

  * Internal mouseOut handler.

  * @9397041 event The MouseEvent passed by the system.

  */

  protected function onMouseOut(event:MouseEvent):void

  {

  _over = false;

  if(!_down)

  {

  _face.filters = [getShadow(1)];

  }

  removeEventListener(MouseEvent.ROLL_OUT, onMouseOut);

  }

  /**

  * Internal mouseOut handler.

  * @9397041 event The MouseEvent passed by the system.

  */

  protected function onMouseDown(event:MouseEvent):void

  {

  _down = true;

  _face.filters = [getShadow(1, true)];

  stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

  }

  /**

  * Internal mouseUp handler.

  * @9397041 event The MouseEvent passed by the system.

  */

  

  protected function onMouseUp(event:MouseEvent):void

  {

  if(_toggle  && _over)

  {

  _selected = !_selected;

  }

  _down = _selected;

  _face.filters = [getShadow(1, _selected)];

  stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);

  }

  ///////////////////////////////////

  // getter/setters

  ///////////////////////////////////

  /**

  * Sets / gets the label text shown on this Pushbutton.

  */

  public function set label(str:String):void

  {

  _labelText = str;

  draw();

  }

  public function get label():String

  {

  return _labelText;

  }

  public function set selected(value:Boolean):void

  {

  if(!_toggle)

  {

  value = false;

  }

  _selected = value;

  _down = _selected;

  _face.filters = [getShadow(1, _selected)];

  }

  public function get selected():Boolean

  {

  return _selected;

  }

  public function set toggle(value:Boolean):void

  {

  _toggle = value;

  }

  public function get toggle():Boolean

  {

  return _toggle;

  }

  }

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 16, 2016

your component class needs to extend or implement an event displatcher.

but it may already do that and you just need to change the names of onMouseUp, for example, to onMouseUpF.