panel
04-12-2007, 09:47 AM
Hi
I have created class ColorPicker. My problem is that I added 2 Sprites and all mouse events are dispatched from Sprites although i added eventlistener directly to class.
evt.target // [Object Sprite]
In class I have access to all methods, but when I am using listners outside class i can't get acces to class methods, becouse evt.target isSprite not ColorPicker
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class ColorPicker extends Sprite
{
private var _border:Sprite;
private var _colorFill:Sprite;
private var _color:uint;
public function ColorPicker(color:uint)
{
_color = color;
_border = new Sprite();
_border.graphics.beginFill(0x000000);
_border.graphics.drawRect(0,0,15,15);
_border.graphics.endFill();
_colorFill = new Sprite();
_colorFill.graphics.beginFill(color)
_colorFill.graphics.drawRect(1,1,13,13)
_colorFill.graphics.endFill();
addChild(_border);
addChild(_colorFill);
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
}
private function onMouseOver(evt:MouseEvent):void
{
trace(evt.target) // [Object Sprite]
}
public function getcolor():String
{
return _color;
}
}
}
package
{
import flash.display.Sprite;
import ColorPicker;
import flash.events.MouseEvent;
public class Test extends Sprite
{
privare var _colorPicker:ColorPicker;
public function Test()
{
_colorPicker:ColorPicker = newColorPicker(0xFF0000);
_colorPicker.addEventListener(MouseEvent.MOUSE_OVE R, onMouseOver);
}
addChild(_colorPicker);
}
private function onMouseOver(evt:MouseEvent):void
{
trace(evt.target) // [Object Sprite]
//also Sprite not ColorPicker so can't access getColor() function
}
}
}
I tryied drawing objects directly in class wihhout using sprites. I works (trace(evt.target) // [Object ColorPicker]), but I don't have any controll over objects in class.
I have created class ColorPicker. My problem is that I added 2 Sprites and all mouse events are dispatched from Sprites although i added eventlistener directly to class.
evt.target // [Object Sprite]
In class I have access to all methods, but when I am using listners outside class i can't get acces to class methods, becouse evt.target isSprite not ColorPicker
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class ColorPicker extends Sprite
{
private var _border:Sprite;
private var _colorFill:Sprite;
private var _color:uint;
public function ColorPicker(color:uint)
{
_color = color;
_border = new Sprite();
_border.graphics.beginFill(0x000000);
_border.graphics.drawRect(0,0,15,15);
_border.graphics.endFill();
_colorFill = new Sprite();
_colorFill.graphics.beginFill(color)
_colorFill.graphics.drawRect(1,1,13,13)
_colorFill.graphics.endFill();
addChild(_border);
addChild(_colorFill);
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
}
private function onMouseOver(evt:MouseEvent):void
{
trace(evt.target) // [Object Sprite]
}
public function getcolor():String
{
return _color;
}
}
}
package
{
import flash.display.Sprite;
import ColorPicker;
import flash.events.MouseEvent;
public class Test extends Sprite
{
privare var _colorPicker:ColorPicker;
public function Test()
{
_colorPicker:ColorPicker = newColorPicker(0xFF0000);
_colorPicker.addEventListener(MouseEvent.MOUSE_OVE R, onMouseOver);
}
addChild(_colorPicker);
}
private function onMouseOver(evt:MouseEvent):void
{
trace(evt.target) // [Object Sprite]
//also Sprite not ColorPicker so can't access getColor() function
}
}
}
I tryied drawing objects directly in class wihhout using sprites. I works (trace(evt.target) // [Object ColorPicker]), but I don't have any controll over objects in class.