Hey everyone
A made a class to make thumbs from loaded images.
I add a listener to every thumb to trigger a event in the main swf.
Already found ‘dispatchEvent’
I can’t seen to find a way to see what thumb called the event.
I need this info to apply some tween’s to the thumb triggering the event
Here you have the code from the class
package classlibrary{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.filters.DropShadowFilter;
public class MenuBuilder extends Sprite {
private var list:XML;
private var _mytestvar:String;
private var _thumb_mc:Sprite;
private var _squar_mc:Sprite;
private var _thumb_pm:Bitmap;
private var dropShadow:DropShadowFilter;
private var _thumbMenu_mc:Sprite = new Sprite();
public function MenuBuilder (list,loader) {
dropShadow = new DropShadowFilter(2.5,45,0x000000,0.3,2,2,1,1,true);
var _Witdh:Number = 0;
var _Xpos:Number = 0;
for (var i:Number =0; i< list.foto.length(); i++) {
_thumb_mc = new Sprite();
_squar_mc = new Sprite();
_thumb_pm = loader.getBitmap("x" + i);
_squar_mc.graphics.beginFill (0xCCCCCC);
_squar_mc.graphics.drawRoundRect (-15, -15, _thumb_pm.width+30, _thumb_pm.height+30, 20, 20);
_squar_mc.graphics.endFill ();
_thumb_pm.filters = [dropShadow];
_thumb_mc.addChild (_thumb_pm);
_thumb_mc.name = "x" + i;
_thumb_mc.x = _Witdh + _Xpos + 10;
_thumb_mc.scaleX = _thumb_mc.scaleY = 0.2;
_Xpos = _thumb_mc.x;
_Witdh = _thumb_mc.width;
_thumbMenu_mc.y = 300;
_thumbMenu_mc.x = 0;
_thumbMenu_mc.name = 'thumbMenu'
_thumb_mc.addChildAt (_squar_mc,0);
_thumbMenu_mc.addChild (_thumb_mc);
_thumb_mc.addEventListener (MouseEvent.CLICK, Click);
_thumb_mc.addEventListener (MouseEvent.ROLL_OVER, Over);
_thumb_mc.addEventListener (MouseEvent.ROLL_OUT, Out);
addChild ( _thumbMenu_mc);
}
}
private function Click (event:MouseEvent):void {
dispatchEvent (new Event ('Click'));
}
private function Over (event:MouseEvent):void {
dispatchEvent (new Event ('Over'));
}
private function Out (event:MouseEvent):void {
dispatchEvent (new Event ('Out'));
}
}
}
and here the code i have in my swf
function callBuilder ( e:Event):void {
var thumbBuilder:MenuBuilder = new MenuBuilder(xmlData,loader);
thumbBuilder.addEventListener ('Click', thumbClick);
thumbBuilder.addEventListener ('Over', thumbOver);
thumbBuilder.addEventListener ('Out', thumbOut);
addChild (thumbBuilder);
}
function thumbClick ( e:Event):void {
trace (e.target.name);
}
function thumbOver ( e:Event):void {
trace ("thumbOver");
}
function thumbOut ( e:Event):void {
trace ("thumbOut");
}
Anyone any ideas ?