HELP (please)! Creating a function shared by different instances...
Hello,
Hoping someone here can help me out with this. It's been forever since I've done any AS3 coding (I wasn't all that fluent to begin with) and I'm stuck.
Basically, I have 3 objects (that need to behave like buttons) on my stage which I'd like to apply the same function to, so I don't have to code each one individually. I was trying to use an array to do this, but as previously mentioned, my concepts seem to out do my actual coding skills. The function should apply a dropshadow filter to the objects. When rolled over or clicked, the shadow of the individual objects would react accordingly (it changes the distance and alpha for each).
Here's where I'm at, which is obviously wrong...
Code:
var list:Array = [
Pic1_10_btn,
Pic1_11_btn,
Pic1_12_btn
];
var overShadow:DropShadowFilter = new DropShadowFilter();
defaultShadow.color = 0x000000;
defaultShadow.blurY = 16;
defaultShadow.blurX = 16;
defaultShadow.angle = 45;
defaultShadow.alpha = .6;
defaultShadow.distance = 5;
var defaultShadow:DropShadowFilter = new DropShadowFilter();
overShadow.color = 0x000000;
overShadow.blurY = 12;
overShadow.blurX = 12;
overShadow.angle = 45;
overShadow.alpha = .7;
overShadow.distance = 4;
var clickShadow:DropShadowFilter = new DropShadowFilter();
clickShadow.color = 0x000000;
clickShadow.blurY = 8;
clickShadow.blurX = 8;
clickShadow.angle = 45;
clickShadow.alpha = .8;
clickShadow.distance = 3;
var filtersArray:Array = new Array(defaultShadow);
function setupPics(pic:SimpleButton, index:int, array:Array):void {
pic.addEventListener(MouseEvent.CLICK, picClick);
pic.addEventListener(MouseEvent.MOUSE_OVER, picOver);
pic.addEventListener(MouseEvent.MOUSE_OUT, picDefault);
pic.filters = filtersArray;
}
list.forEach(setupPics);
function picDefault(e:MouseEvent):void {
this.filters=[defaultShadow];
}
function picOver(e:MouseEvent):void {
this.filters=[overShadow];
}
function picClick(e:MouseEvent):void {
this.filters=[clickShadow];
}
Assuming this is possible, any help would be greatly appreciated. Thanks in advance!
---
Chris