FLVPlayback stop/play - actionscript-3

Problem with a FLVPlayback component and the stop() play() method. Here is the code of my class, videoPlayer is a FLVPlayback component on the stage. The array holds videos in the format [videos/s1.flv,videos/s2.flv,videos/s3.flv] When I call the stopVideo() function while the first video is still playing it stops and rewinds to frame 1 of the video (working as intended) but then when I call the playVideo() method it doesnt play the video again. It works when I stop the FLVPlayback while its playing the 2nd or 3rd video. I know the READY event isnt invoked at the 1st video because it was invoked at the beginning. What I'm doing wrong?
public class Intro extends MovieClip {
private var intros:XML;
private var currentVideo:uint = 0;
private var _data:XML;
private var videos:Array;
public function Intro(data:XML) {
_data = data;
videoPlayer.addEventListener(VideoEvent.COMPLETE, completeHandler);
videoPlayer.addEventListener(VideoEvent.READY, videoReady);
videoPlayer.opaqueBackground = 0x000000;
videoPlayer.autoRewind = true;
}
function completeHandler(evt:Event):void {
trace("video complete");
currentVideo++;
if (currentVideo < videos.length) {
videoPlayer.source = videos[currentVideo];
} else {
currentVideo = 0;
}
}
public function playVideo():void {
trace(currentVideo);
if (currentVideo == 0) {
trace(videos[currentVideo]);
videoPlayer.play(videos[currentVideo]);
} else {
videoPlayer.source = videos[currentVideo];
}
}
public function prepareVideos(introVideos:XML):void {
intros = introVideos;
var list:XMLList = intros.entry;
var entry:XML;
var len:int = list.length();
videos = new Array();
for (var i:int = 0; i < len; i++) {
entry = list[i];
videos.push(entry);
}
dispatchEvent(new Event(Event.COMPLETE));
}
public function stopVideo():void {
if (videoPlayer.playing) {
trace("video stopped");
videoPlayer.stop();
currentVideo = 0;
}
}
private function resetVideo(e:VideoEvent):void {
videoPlayer.seek(0);
}
private function videoReady(e:VideoEvent):void {
trace("video ready");
videoPlayer.play();
}
}

you only want to specificy the video name in the play method when first playing the video. after that (ie, after applying a stop() )just use the play() method with no parameter

Related

How do I stop my Flash (AS3) program's framerate from dropping when users go to a new tab in their browser?

Every time I run my Flash program in a browser, the framerate drops from 30 to ~2 whenever I go to a different tab. Is there a way to stop the background framerate from tanking whenever the window isn't in focus? The framerate doesn't go down if I open a new window in the browser, even if the window covers the window with the Flash program. I'm also working in FlashDevelop if that helps. Thanks!
Unearthed some source code from 2014 and found what I ended up going with:
HUD.as:
public var idle:Boolean = false;
public var catchingUp:Boolean = false;
private var secondsIdle:int = 0;
stage.addEventListener(Event.DEACTIVATE, StartIdleMode);
stage.addEventListener(Event.ACTIVATE, RegainedFocus);
public function Update(sta:DisplayObjectContainer, save:SharedObject):void
{
//...The game logic that happens every frame...
if (secondsIdle < 0)
{
idle = true;
}
}
private function StartIdleMode(e:Event):void
{
var date:Date = new Date();
secondsIdle = date.valueOf();
}
private function RegainedFocus(e:Event):void
{
if (idle)
{
var diffDate:Date = new Date();
secondsIdle += -(diffDate.valueOf() / 2);
catchingUp = true;
}
}
public function CatchUp(sta:DisplayObjectContainer, save:SharedObject):void
{
var tempFrames:int = Math.floor(secondsIdle / 1000 * 30);
while (tempFrames < 0)
{
this.Update(sta, save);
tempFrames++;
}
idle = false;
catchingUp = false;
secondsIdle = 0;
}
Main.as:
private var gameTimer:Timer = new Timer(1000 / 30, 0);
private var hud:HUD;
public function Main():void
{
gameTimer.addEventListener(TimerEvent.TIMER, GameLoop);
gameTimer.start();
}
private function GameLoop(e:TimerEvent):void
{
if (!hud.idle)
{
hud.Update(stage, gameSystem.saveData);
}
if (hud.catchingUp)
{
hud.CatchUp(stage, gameSystem.saveData);
}
}

How to make a movie clip visible if only five movie clips (not more) are clicked

I have 25 movie clips on stage and they all can be clicked and colored. I want a movie clip named text_mc to became visible if only 5 specific buttons from those are clicked and colored - not more. If the user choose more than those five movie clips (even thought that 5 movie clips are included) then the movie clip named text_mc should stay invisible. I can' t do the last part: if more than those 5 specific movie clips are clicked then the text_mc should stay invisible. Can you please help me? This is my code
stop();
import flash.display.MovieClip;
var sximata:MovieClip = square1;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
text_mc.visible=false;
square1.addEventListener(MouseEvent.CLICK, onsquare1);
function onsquare1(e:MouseEvent):void {
sximata = square1;
}
square2.addEventListener(MouseEvent.CLICK, onsquare2);
function onsquare2(e:MouseEvent):void {
sximata = square2;
}
square3.addEventListener(MouseEvent.CLICK, onsquare3);
function onsquare3(e:MouseEvent):void {
sximata = square3;
}
square4.addEventListener(MouseEvent.CLICK, onsquare4);
function onsquare4(e:MouseEvent):void {
sximata = square4;
}
square5.addEventListener(MouseEvent.CLICK, onsquare5);
function onsquare5(e:MouseEvent):void {
sximata = square5;
}
square6.addEventListener(MouseEvent.CLICK, onsquare6);
function onsquare6(e:MouseEvent):void {
sximata = square6;
}
square7.addEventListener(MouseEvent.CLICK, onsquare7);
function onsquare7(e:MouseEvent):void {
sximata = square7;
}
square8.addEventListener(MouseEvent.CLICK, onsquare8);
function onsquare8(e:MouseEvent):void {
sximata = square8;
square8Clicked = true;
checkButtons();
}
square9.addEventListener(MouseEvent.CLICK, onsquare9);
function onsquare9(e:MouseEvent):void {
sximata = square9;
square9Clicked = true;
checkButtons();
}
square10.addEventListener(MouseEvent.CLICK, onsquare10);
function onsquare10(e:MouseEvent):void {
sximata = square10;
square10Clicked = true;
checkButtons();
}
square11.addEventListener(MouseEvent.CLICK, onsquare11);
function onsquare11(e:MouseEvent):void {
sximata = square11;
}
square12.addEventListener(MouseEvent.CLICK, onsquare12);
function onsquare12(e:MouseEvent):void {
sximata = square12;
}
square13.addEventListener(MouseEvent.CLICK, onsquare13);
function onsquare13(e:MouseEvent):void {
sximata = square13;
square13Clicked = true;
checkButtons();
}
square14.addEventListener(MouseEvent.CLICK, onsquare14);
function onsquare14(e:MouseEvent):void {
sximata = square14;
square14Clicked = true;
checkButtons();
}
square15.addEventListener(MouseEvent.CLICK, onsquare15);
function onsquare15(e:MouseEvent):void {
sximata = square15;
}
square16.addEventListener(MouseEvent.CLICK, onsquare16);
function onsquare16(e:MouseEvent):void {
sximata = square16;
}
square17.addEventListener(MouseEvent.CLICK, onsquare17);
function onsquare17(e:MouseEvent):void {
sximata = square17;
}
square18.addEventListener(MouseEvent.CLICK, onsquare18);
function onsquare18(e:MouseEvent):void {
sximata = square18;
}
square19.addEventListener(MouseEvent.CLICK, onsquare19);
function onsquare19(e:MouseEvent):void {
sximata = square19;
}
square20.addEventListener(MouseEvent.CLICK, onsquare20);
function onsquare20(e:MouseEvent):void {
sximata = square20;
}
square21.addEventListener(MouseEvent.CLICK, onsquare21);
function onsquare21(e:MouseEvent):void {
sximata = square21;
}
square22.addEventListener(MouseEvent.CLICK, onsquare22);
function onsquare22(e:MouseEvent):void {
sximata = square22;
}
square23.addEventListener(MouseEvent.CLICK, onsquare23);
function onsquare23(e:MouseEvent):void {
sximata = square23;
}
square24.addEventListener(MouseEvent.CLICK, onsquare24);
function onsquare24(e:MouseEvent):void {
sximata = square24;
}
square25.addEventListener(MouseEvent.CLICK, onsquare25);
function onsquare25(e:MouseEvent):void {
sximata = square25;
}
var myColorTransform:ColorTransform=transform.colorTransform;
red_btn.addEventListener(MouseEvent.CLICK, changeColour);
function changeColour(event:MouseEvent):void {
myColorTransform.color=0xBD8D46;
sximata.transform.colorTransform=myColorTransform;
}
resetButton.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
gotoAndPlay(1);
}
var square8Clicked:Boolean = false;
var square9Clicked:Boolean = false;
var square10Clicked:Boolean = false;
var square13Clicked:Boolean = false;
var square14Clicked:Boolean = false;
function checkButtons():void
{
if(square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
{
text_mc.visible = true;
}
}
You could add a boolean variable to each of the other functions that turns to true if any of the other squares are clicked. For example:
var isClicked:Boolean = false;
square1.addEventListener(MouseEvent.CLICK, onsquare1);
function onsquare1(e:MouseEvent):void {
sximata = square1;
isClicked = true;
}
And then in your check buttons function, check to see if "isClicked" is still false:
function checkButtons():void
{
if(!isClicked && square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
{
text_mc.visible = true;
}
}
My solution is below. It's based on counting the number of clicks received by each type of MovieClip the user can click on.The relevant parts of the code would be in the onClick() and checkClickCounts() methods.
First, you'll see that in the buildMCs() method I simply create a bunch of MovieClips and place them on the stage in a grid. I've made it so that the "specific" MCs that you mention are the first items on each row of the grid. To each of these "specific" MCs, I've added a property: isSpecial:Boolean and set it to true. Later, when a MC is clicked, the OnClick() method will check to see if the MC was special or not, and will increment the relevant click count property. Then, checkClickCounts() is called. If 5 good clicks and 0 bad clicks are counted up, then we let the user know. This is where you'd display your textfield. (In my case, I just draw a big red rectangle on the screen.
Another suggestion I demo here is to avoid repeating your mouse click code. If you look in the constructor, you'll see that I used this line:
this.addEventListener(MouseEvent.CLICK, onClick);
This tells the main stage sprite to listen to all mouse clicks, even the ones that happen to MovieClips inside of it. In the onClick() method I check to see if the item clicked - the target of the event - was a MovieClip. If it was, then I do the additional checking to see if the MC clicked was one that I wanted. By doing this, I was able to write the code for handling the mouse clicks once, and now if I need to change something, I only have to do it one time, rather than 25 times. Saves me time, but also makes the code less error-prone because I'm less likely to miss something if there's a change that needs to be made.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Clicky extends Sprite
{
public function Clicky()
{
this.buildMCs();
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function buildMCs ():void
{
var rows:int = 5;
var cols:int = 5;
var boxSize:int = 10;
for (var r:int = 0; r < rows; r++)
{
for (var c:int = 0; c < cols; c++)
{
var newMC:MovieClip = new MovieClip();
newMC.graphics.lineStyle(0, 0x00ff00);
// want to mark the "specific" movieclips
if (c == 0)
{
newMC.graphics.beginFill(0x0000ff);
// just something that makes this MC unique... ideally
// this would be not a MovieClip, but a class that defines
// actual properties worth checking for
newMC.isSpecial = true;
}
else
{
newMC.graphics.beginFill(0x00ff00);
}
newMC.graphics.drawRect(0, 0, boxSize, boxSize);
this.addChild(newMC);
newMC.x = (c * boxSize);
newMC.y = (r * boxSize);
}
}
}
private function onClick (e:MouseEvent):void
{
if (e.target is MovieClip)
{
var mc:MovieClip = e.target as MovieClip;
mc.alpha = .25;
// disable the clicking for the clicked item
mc.mouseEnabled = false;
if (mc.isSpecial)
{
_specialClicks++;
}
else
{
_badClicks++;
}
this.checkClickCounts();
}
}
private var _specialClicks:int = 0;
private var _badClicks:int = 0;
private function checkClickCounts ():void
{
if (_specialClicks == 5 && _badClicks == 0)
{
// do your thing - show the text_mc, play a sound, award a prize, etc.
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0, 0, 1000, 1000);
}
}
}
}

got Error #1009 in flash as3

i'm new in flash and as3 programming, and this is my first project. i found error on my project like this
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at src.char::Enemy/Remove()
at src.screen::Gameplay/Collision()
at src.screen::Gameplay/Routine()
I think the error occurs because there is no function Remove () on the gameplay, but I'm not sure that's true. here's the enemy.as
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Enemy extends MovieClip {
private var timer:Timer = new Timer(25);
public function Enemy(xPos:Number, yPos:Number) {
x = xPos;
y = yPos;
timer.addEventListener(TimerEvent.TIMER, MoveDown);
timer.start();
}
private function MoveDown(e:TimerEvent):void {
y += 3;
if (y>400) {
Remove();
}
}
public function Remove():void {
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, MoveDown);
parent.removeChild(this);
}
}
and here's the the gameplay.as
public class Gameplay extends MovieClip {
private var timer:Timer = new Timer(500);
private var player:Player;
public function Gameplay() {
addEventListener(Event.ADDED_TO_STAGE, InitKeyboard);
addEventListener(Event.ENTER_FRAME, Routine);
gameplayBack.addEventListener(MouseEvent.CLICK, GoToMap);
timer.addEventListener(TimerEvent.TIMER, OnTick);
timer.start();
InitPlayer();
InitLifePoint();
}
private function InitLifePoint():void {
lifePoint.gotoAndStop(1);
}
private function Routine(e:Event):void {
Collision();
}
private function Collision():void {
for (var i:int = 0; i < enemies.length; i++ ) {
if (player.hitTestObject(enemies[i])) {
PlayerHit();
enemies[i].Remove();
return;
}else {
for (var j:int = 0; j < bullets.length; j++ ) {
if (bullets[j].hitTestObject(enemies[i])) {
layerParticle.addChild(new Blast(bullets[j].x, bullets[j].y));
layerParticle.addChild(new Smoke(bullets[j].x, bullets[j].y));
bullets[j].Remove();
enemies[i].Remove();
scorePlay.text = int(scorePlay.text) + 10 + "";
trace(scorePlay.text);
return;
}
}
}
}
}
private var life:int = 1000;
private var currentLife:int = 1000;
private function PlayerHit():void {
currentLife -= 100;
if (currentLife <= 0) {
lifePoint.gotoAndStop(100);
GameOver();
}else {
lifePoint.gotoAndStop(100 - currentLife / life * 100);
}
}
private var result:Result = new Result();
private function GameOver():void {
result.youWin.alpha = 0;
result.ok.addEventListener(MouseEvent.CLICK, GoToMap);
result.x = 0;
result.y = 0;
addChild(result);
}
private function InitKeyboard(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, InitKeyboard);
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
}
private function KeyDown(e:KeyboardEvent):void {
switch(e.keyCode) {
case Keyboard.LEFT: MoveLeft(); break;
case Keyboard.RIGHT: MoveRight(); break;
case Keyboard.SPACE: Fire(); break;
}
}
private var bullets:Array = new Array();
private function Fire():void {
var bullet:Bullet = new Bullet(player.x, player.y);
bullet.scaleX = 0.25;
bullet.scaleY = 0.25;
bullet.addEventListener(Event.REMOVED_FROM_STAGE, RemoveBulletArray);
layerParticle.addChild(bullet);
bullets.push(bullet);
}
private function RemoveBulletArray(e:Event):void {
removeEventListener(Event.REMOVED_FROM_STAGE, RemoveBulletArray);
var index:int = bullets.indexOf(Bullet(e.currentTarget), 0);
bullets.splice(index, 1);
}
private function MoveRight():void {
if (player.x < 550) {
player.x += 5;
}
}
private function MoveLeft():void {
if (player.x > 0) {
player.x -= 5;
}
}
private function InitPlayer():void {
player = new Player(550 * 0.5, 350);
layerChar.addChild(player);
}
private function OnTick(e:TimerEvent):void {
RandomEnemy();
}
private var enemies:Array = new Array();
private function RandomEnemy():void {
var enemy:Enemy = new Enemy(Math.random() * 550, 0);
enemy.addEventListener(Event.REMOVED_FROM_STAGE, RemoveFromArray);
layerChar.addChild(enemy);
enemies.push(enemy);
}
private var remaining:int = 10;
private function RemoveFromArray(e:Event):void {
removeEventListener(Event.REMOVED_FROM_STAGE, RemoveFromArray);
var index:int = enemies.indexOf(Enemy(e.currentTarget), 0);
enemies.slice(index, 1);
remaining--;
if (remaining == 0) GameWin();
}
private function GameWin():void {
result.youLose.alpha = 0;
result.score.text = scorePlay.text;
result.ok.addEventListener(MouseEvent.CLICK, GoToMap);
result.x = 0;
result.y = 0;
addChild(result);
}
private function GoToMap(e:MouseEvent):void {
dispatchEvent(new ScreenEvent(ScreenEvent.MAP));
}
}
Your problem is a NPE (Null Pointer Exception/Error) inside the Enemy.Remove() method:
public function Remove():void {
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, MoveDown);
parent.removeChild(this);
}
Either your timer property is null (which I doubt, looking at your code) or the parent property are.
In a MovieClip the parent property are filled with a DisplayObject if your MovieClip is added to it, if not, this property is null.
Your problem probably is that you are removing (from its parent) this MovieClip more than once, or is trying to remove it without adding it first.
To make sure this is the problem, add a if statement to check the parent property first, like this:
if(parent != null)
{
parent.removeChild(this);
}
Note:
This may solve your NPE problem, but will not solve what is causing it, which may lead you into more and more inexplicable bugs.
Double check your logic to make sure you're removing a previously added MovieClip, or that you aren't removing it more than once.
Do you notice the flaw in the Collision function, if you observe like this:
for (var i:int = 0; i < enemies.length; i++) {
if (~) {
...
enemies[i].Remove();
...
} else {
for (~) {
if (~) {
...
enemies[i].Remove();
...
}
}
}
}
Apparently, in the second for loop you could be easily referencing the same Enemy Object.
And the problem comes after you call Remove function, because by doing parent.removeChild(this); you remove the only reference of the object to it's parent object.
You can try to do one of these:
Keep a reference to the parent object in the class, manually.
Keep a state variable in the class to check if it is to be a part of display list or not.
Move the enemies[i].Remove(); code into outermost loop.
If possile, recycle the object. Especially, when you are just
moving (x,y) the movieclip around.

Flash events execution order

Check out the next code, tell me what do you expect to be printed. Then run it and check what is really happen.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class TestFlashEvents extends Sprite
{
private static const DUMMY_EVENT:String = "DummyEvent";
private var dummyObjects:Vector.<DummyObject> = new Vector.<DummyObject>(100);
public function TestFlashEvents()
{
for(var i:int = 0; i < dummyObjects.length; i++){
dummyObjects[i] = new DummyObject(this);
addEventListener(DUMMY_EVENT, dummyObjects[i].listener);
}
removeEventListener(DUMMY_EVENT, dummyObjects[41].listener);
dispatchEvent(new Event(DUMMY_EVENT));
}
private var counter:int = 0;
public function onGettingEvent(dummyObject:DummyObject):void{
if(counter == 25){
for(var i:int = 0; i < 50; i++){
removeEventListener(DUMMY_EVENT, dummyObjects[i].listener);
trace("Removing", dummyObjects[i].id);
}
}
trace("Handeling event", counter, dummyObject.id);
counter++;
}
}
}
import flash.events.Event;
class DummyObject
{
private static var dummyObjectsCounter:int = 0;
public var id:String;
private var tester:TestFlashEvents;
public function DummyObject(tester:TestFlashEvents)
{
this.tester = tester;
id = "DummyObject " + dummyObjectsCounter;
dummyObjectsCounter++;
}
public function listener(event:Event):void{
tester.onGettingEvent(this);
}
}
The removeEventListener function is actually not working. Tell me what do you think about it. I also open a bug in adobe.
This code means Adobe caches event listener list prior to actually calling event listeners. It is an unusual behavior to have two listeners for one particular event over one single object, but if it happens, Adobe assumed that all listeners should be invoked prior to actually modifying this list. I was actually expecting all 99 listeners to get called. So, this behavior can even be by design, because re-rendering the event listener list while processing a single event will put a too heavy load on Flash, so that the lags will galore. No one wants lags.
This can easily be fixed by prioritizing you event listeners.
This is not a Flash bug, it is, like Vesper said caching of event listeners to prevent lag.
Here is the updated version of your code, mark the prioritizing on the addEventListener call.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class TestFlashEvents extends Sprite
{
private var _this = this;
private static const DUMMY_EVENT:String = "DummyEvent";
private var dummyObjects:Vector.<DummyObject> = new Vector.<DummyObject>(100);
public function TestFlashEvents()
{
for(var i:int = 0; i < dummyObjects.length; i++)
{
dummyObjects[i] = new DummyObject(this);
addEventListener(DUMMY_EVENT, dummyObjects[i].listener, false, dummyObjects.length - i);
}
removeEventListener(DUMMY_EVENT, dummyObjects[41].listener);
dispatchEvent(new Event(DUMMY_EVENT));
}
private var counter:int = 0;
public function onGettingEvent(dummyObject:DummyObject):void
{
if (counter == 25)
{
for (var i:int = 0; i < 50; i++)
{
removeEventListener(DUMMY_EVENT, dummyObjects[i].listener);
trace("Removing", dummyObjects[i].id);
}
}
trace("Handeling event", counter, dummyObject.id);
counter++;
}
}
}
import flash.events.Event;
class DummyObject
{
private static var dummyObjectsCounter:int = 0;
public var id:String;
private var tester:TestFlashEvents;
public function DummyObject(tester:TestFlashEvents)
{
this.tester = tester;
id = "DummyObject " + dummyObjectsCounter;
dummyObjectsCounter++;
}
public function listener(event:Event):void{
tester.onGettingEvent(this);
}
}

Add an array of Movie Clips to a filter ActionScript 3

i stored 8 mc's in an array an i put them on the stage.
now I want to apply to these mc's a blur effect.
My problem is that i don't know how to apply for every mc the blur effect by clicking on it.
So for example I have all the mc's on the stage and if I click on one of them the clicked one should have the blur effect and so on.
How to apply the filter to the mc's?
Thank you for you time
You can loop through the mc's array and add event listeners on each of them:
var mcArrayLength:int = mcArray.length();
for (var i:int = 0; i < mcArrayLength; i++) {
var mc:MovieClip = mcArray[i] as MovieClip;
mc.addEventListener(MouseEvent.CLICK, onMcClick);
}
and the event handler:
function onMcClick(e:MouseEvent):void
{
var clickedMc:MovieClip = e.currentTarget as MovieClip;
clickedMc.filters = [myBlurFilter];
}
of course, if you wanted to have only one blurred mc at a time, you should keep a reference to it and remove blur once another mc is clicked:
var currentlyClickedMc:MovieClip;
function onMcClick(e:MouseEvent):void
{
var clickedMc:MovieClip = e.currentTarget as MovieClip;
clickedMc.filters = [myBlurFilter];
if (currentlyClickedMc) currentlyClickedMc.filters = [];
currentlyClickedMc = clickedMc;
}
something like this (untested) should work:
package
{
//Imports
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
//Class
public function ClickToBlur
{
//Variables
private var clickableObjects:Array;
//Constructor
public function ClickToBlur(clickableObjects:Array)
{
this.clickableObjects = clickableObjects;
init();
}
//Initialize
private function init():void
{
for each (var object:Object in clickableObjects)
{
object.addEventListener(MouseEvent.CLICK, clickMouseEventHandler);
}
}
//Click Mouse Event Handler
private function clickMouseEventHandler(evt:MouseEvent):void
{
if (evt.currentTarget.filters == [])
{
evt.currentTarget.filters = [new BlurFilter()];
}
else
{
evt.currentTarget.filters = [];
}
}
//Dispose
public function dispose():void
{
for each (var object:Object in clickableObjects)
{
object.removeEventListener(MouseEvent.CLICK, clickMouseEventHandler);
}
}
}
}
just pass your array to a new instance of the class
var ctb:Object = new ClickToBlur(myArrayOfObjects);
and clean up when your done:
ctb.dispose();
since they're all Movie Clips, you should use a Vector instead of an Array.