Hello, this is my first post here, I’ve found kirupa overall a great help so far but I’ve stumbled upon one thing that I just can’t figure out.
What I want to do visually is to create a waveform that moves from left to right and never ends. So I created a WaveCycle class that contains the total waveform on the stage. and a Wave class that contains a single wave-part like so ~
I thought it would be ideal if the first wave-part generates the second and so on and where the wave should end on the right they remove themselves.
Everything works so far except for having each wave part generate the next part. For this I am trying to use dispatchEvent because the WaveCycle class creates the parts.
(Some parts of the code don’t serve a purpose atm)
This is the WaveCycle class:
/**
* ...
* @author Default
* @version 0.1
*/
import mx.utils.Delegate;
import org.tween.TweenLite;
import mx.transitions.easing;
class WaveCycle
{
public function WaveCycle()
{
makeNew();
}
function addEventListener() {};
function removeEventListener() {};
public function newWave():Void {
trace("nieuw!");
}
private function makeNew():Void {
var myWave:Wave = new Wave(_level0.contentMC.bronMC.wavesMC, 100, 100, 300, 220, 5, 5, "bron_wave");
var listener:Object = new Object();
listener.newWave = function(e:Object)
{
_global.tt("TEST");
}
myWave.addEventListener("newWave", listener);
}
}
and this is the Wave class:
/**
* ...
* @author Default
* @version 0.1
*/
import org.tween.TweenLite;
import mx.transitions.easing.Bounce;
import mx.events.EventDispatcher;
import mx.transitions.Tween;
import mx.utils.Delegate;
class Wave {
private static var EventDispatcherDependancy = EventDispatcher.initialize(Wave.prototype);
public var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
//function dispatchEvent() {};
//function addEventListener() {};
//function removeEventListener() {};
private var __tweenmc:MovieClip;
private var __targetmc:MovieClip;
private var __startx:Number;
private var __starty:Number;
private var __endx:Number;
private var __fadex:Number;
private var __xduration:Number;
private var __fduration:Number;
private var __tweenobject:String;
private var __number:Number = new Number(0);
private var __myTween:TweenLite;
/**
*
* @param targetmc
* @param startx
* @param starty
* @param endx
* @param fadex
* @param xduration
* @param fduration
* @param tweenobject
*/
public function Wave(targetmc:MovieClip,startx:Number,starty:Number,endx:Number,fadex:Number,xduration:Number,fduration:Number,tweenobject:String) {
__targetmc = targetmc;
__startx = startx;
__starty = starty;
__endx = endx;
__fadex = fadex;
__xduration = xduration;
__fduration = fduration;
__tweenobject = tweenobject;
buildWave();
}
public function buildWave():Void {
__number++;
__tweenmc = __targetmc.attachMovie(__tweenobject, "wave" + __number, __targetmc.getNextHighestDepth());
__tweenmc._x = __startx;
__tweenmc._y = __starty;
__myTween = TweenLite.to(__tweenmc, __xduration,{_x:__fadex});
__myTween = TweenLite.to(__tweenmc, 2, {_alpha:0,overwrite:false, delay:2, onComplete:killWave, onCompleteParams:[__tweenmc]});
__myTween = TweenLite.delayedCall(.5, nextWave, [__tweenmc]);
}
public function nextWave(__mc):Void {
this.dispatchEvent({type:"newWave",target:this});
}
public function killWave(__mc):Void {
__mc.removeMovieClip();
}
}
how can I get EventDispatcher to work for me in this situation?
Thanks for reading!