Hello there
I am having a little trouble invalidating tweens which were created as functions using the transform matrix plugin.
This is the code i am using (I am still quite new to flash to please be kind and if anyone has any suggestions as to how to improve it that would be most appreciated!)
stop();
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
OverwriteManager.init(2)
TweenPlugin.activate([TransformMatrixPlugin]);
job_1.addEventListener(MouseEvent.CLICK, overJ1);
job_2.addEventListener(MouseEvent.CLICK, overJ2);
job_3.addEventListener(MouseEvent.CLICK, overJ3);
job_4.addEventListener(MouseEvent.CLICK, overJ4);
job_5.addEventListener(MouseEvent.CLICK, overJ5);
job_6.addEventListener(MouseEvent.CLICK, overJ6);
function overJ1(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-875, y:0, scaleX:2.5, scaleY:2.5, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
function overJ2(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-875, y:0, scaleX:2.49, scaleY:2.49, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
function overJ3(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-300, y:50, scaleX:1.98, scaleY:1.98, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
function overJ4(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-700, y:50, scaleX:1.98, scaleY:1.98, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
function overJ5(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-930, y:50, scaleX:1.98, scaleY:1.98, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
function overJ6(event:MouseEvent):void {
TweenMax.to(event.target, 0.25, {transformMatrix:{x:-800, y:0, scaleX:2.49, scaleY:2.49, ease:Elastic.easeOut}});
addChildAt(DisplayObject(event.target), numChildren-1);
}
btn_close1.addEventListener(MouseEvent.CLICK, outJ1);
btn_close2.addEventListener(MouseEvent.CLICK, outJ2);
btn_close3.addEventListener(MouseEvent.CLICK, outJ3);
btn_close4.addEventListener(MouseEvent.CLICK, outJ4);
btn_close5.addEventListener(MouseEvent.CLICK, outJ5);
btn_close6.addEventListener(MouseEvent.CLICK, outJ6);
function outJ1(event:MouseEvent):void {
TweenMax.to(job_1, 0.25, {transformMatrix:{x:-1070.0, y:100, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
function outJ2(event:MouseEvent):void {
TweenMax.to(job_2, 0.25, {transformMatrix:{x:-235, y:100, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
function outJ3(event:MouseEvent):void {
TweenMax.to(job_3, 0.25, {transformMatrix:{x:-200, y:720, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
function outJ4(event:MouseEvent):void {
TweenMax.to(job_4, 0.25, {transformMatrix:{x:-1070, y:720, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
function outJ5(event:MouseEvent):void {
TweenMax.to(job_5, 0.25, {transformMatrix:{x:250, y:720, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
function outJ6(event:MouseEvent):void {
TweenMax.to(job_6, 0.25, {transformMatrix:{x:575, y:100, scaleX:1, scaleY:1, ease:Elastic.easeOut}});
gotoAndPlay("close_ad");
}
job_1.addEventListener(MouseEvent.CLICK, buttonClickHandler7);
function buttonClickHandler7(event:MouseEvent):void {
gotoAndStop("job1");
}
job_2.addEventListener(MouseEvent.CLICK, buttonClickHandler8);
function buttonClickHandler8(event:MouseEvent):void {
gotoAndStop("job2");
}
job_3.addEventListener(MouseEvent.CLICK, buttonClickHandler9);
function buttonClickHandler9(event:MouseEvent):void {
gotoAndStop("job3");
}
job_4.addEventListener(MouseEvent.CLICK, buttonClickHandler10);
function buttonClickHandler10(event:MouseEvent):void {
gotoAndStop("job4");
}
job_5.addEventListener(MouseEvent.CLICK, buttonClickHandler11);
function buttonClickHandler11(event:MouseEvent):void {
gotoAndStop("job5");
}
job_6.addEventListener(MouseEvent.CLICK, buttonClickHandler12);
function buttonClickHandler12(event:MouseEvent):void {
gotoAndStop("job6");
}
When buttons Job_1, 2, 3, 4, 5 & 6 are CLICKED the corresponding 'overJ....' function is called where the button gets bigger and the timeline goes to the appropriate frame label. The over function also sets the object to the stop of the stacking order.
Once on the frame label selecting the appropriate instance of 'btn_close_...' ('CLOSE AD' IN THE URL) is then clicked which calls the 'outJ....' function which tweens the object back to its original size as well as sending the timeline to the 'close' frame label which then plays to the end of the movieclip and then returns to the start of the timeline resetting the code -
All this works fine as you can see at the following URL
http://www.thejobgame.eu/ENG/test.html
Note: the 'job_...' buttons are the ones that look like classified ads - when selected the 'CLOSE AD' button appears below
My problem is that when the over function is called - the other 'Job_....' instances can still be selected and if the user were to accidentally click on them things start to go wrong as you can see.
On the "Job..." frame labels I have inserted the following code to try and remove eventListeners for the buttons and kill tweens that are not being used e.g. on label "Job1" i have the following:
job_1.removeEventListener(MouseEvent.CLICK, overJ1);
trace("job 1 listener is removed");
job_2.removeEventListener(MouseEvent.CLICK, overJ2);
trace("job 2 listener is removed");
TweenLite.killTweensOf(job_2);
job_3.removeEventListener(MouseEvent.CLICK, overJ3);
trace("job 3 listener is removed");
TweenLite.killTweensOf(job_3);
job_4.removeEventListener(MouseEvent.CLICK, overJ4);
trace("job 4 listener is removed");
TweenLite.killTweensOf(job_4);
job_5.removeEventListener(MouseEvent.CLICK, overJ5);
trace("job 5 listener is removed");
TweenLite.killTweensOf(job_5);
job_6.removeEventListener(MouseEvent.CLICK, overJ6);
trace("job 6 listener is removed");
TweenLite.killTweensOf(job_6);
The trace statements are called and the tweens for these buttons killed but I am still able to select the other buttons?
You can probably tell that i'm still stuck in sequential mode and this is probably not the best way to go about setting up my files so any alternative suggestions would be great
Many thanks in advance