Hello Everyone,
In an attempt to grow my AS3 knowledge, I’ve created a a custom event class that extends the event class. In it I basically pass a data object, so I can freely pass data between classes. It works great when the object that initiates the event is clicked but I can get it work when I simply run a function. I don’t get errors but nothing happens either the line of code is essential ignored. Here is my current code:
THE CUSTOM EVENT CLASS:
package com.acs
{
import flash.events.Event
public class ThumbEvent extends Event{
private var _data:Object;
public static const PAGETHUMB_CLICK:String = 'pageThumbClick';
public static const THUMBLOAD_COMPLETE:String = 'thumbLoadComplete';
public function ThumbEvent(type:String, obj:Object = null) {
_data = obj;
super(type, true, false);
}
public function get data():Object {
return _data;
}
}
}
Here, I send the dispatch event from another class:
private function buildSlider():void
{
var space:Number = 0;
_slider.container_mc.mask = _slider.mask_mc;
_thumbDir = _xml.@ thumbs;
_fullDir = _xml.@ fulls;
_xmlList = new XMLList(_xml.children());
for (var i:uint = 0; i < _xmlList.length(); i++)
{
var img:String = _thumbDir + _xmlList*. @ img;
var clip:String = _xmlList*.@clip;
var ptitle:String = _xmlList*.title;
var pnum:String = _xmlList*.number;
_pageThumb = new PageThumb(img,clip,ptitle,pnum);
_pageThumb.x = space;
_slider.container_mc.addChild(_pageThumb);
space += _thumbWidth + _thumbPad;
}
dispatchEvent(new ThumbEvent(ThumbEvent.THUMBLOAD_COMPLETE, {allLoaded:"true"}));
scrollContent();
}
And here is the Event Listener that is listening for the event to occur (Note: this code is in my document class which is a completely different class from where the dispatch event is occurring):
private function loadScene():void
{
_scene = new Base(_xml, stage);
addChild(_scene);
_scene.addEventListener(ThumbEvent.THUMBLOAD_COMPLETE, thumbCompleteHandler);
_scene.addEventListener(ThumbEvent.PAGETHUMB_CLICK, thumbClickHandler);
}
private function thumbClickHandler(e:ThumbEvent):void
{
trace(e.data.allLoaded);
}
Again, I’m fairly new to making custom events. I can get this code to work if I initiate it by a button click but I can’t get it to run when its been called from a basic function. Which is what I need here. Any help on what I’m doing wrong here is greatly appreciated.
Thanks!