How do classes in actionscript project override classes in a Flash CS3 SWC file?
I have an actionscript project which uses visual symbols from an SWC.
I have a CheckoutButton
which has the following class associated with it (compiled into the SWC in Flash CS3).
public class CheckoutButton extends SimpleButton {
public function CheckoutButton () {
this.addEventListener(MouseEvent.CLICK, checkoutClicked);
}
// click on the button and the alpha will go to 50%
public function checkoutClicked(e:MouseEvent):void {
this.alpha = .5; // take user to checkout
}
public function dispose ():void {
}
}
Important: The CheckoutButton.as
file is in the classpath for the actionscript project that uses the SWC.
I use the compiled SWC in an actionscript project and I have run the following scenarios :
1) I DELETE CheckoutButton.as
from the classpath for my actionscript project:
var x:CheckoutButton = new CheckoutButton();
addChild(x);
I get an instance of the visual symbol from my Flash CS3 file. When I click on it it's alpha goes to 50%. This again is exactly as i expected.
2) I run this code with CheckoutButton.as
in the classpath for my actionscript project:
var x:CheckoutButton = new CheckoutButton();
addChild(x);
Nothing happens at all. This is exactly as I expect - because I've basically overridden the class definition from the SWC with a SimpleButton
that has no visual functionality whatsoever.
Now I also have a timeline animation CheckoutAni开发者_开发技巧mation
in my Flash file that just happens to contain an instance of the CheckoutButton
symbol.
3) I run the actionscript project after DELETING CheckoutButton.as
from the classpath:
var x:CheckoutAnimation = new CheckoutAnimation();
addChild(x);
The symbol in the animation picks up the class definition (as originally compiled into the SWC) and when I click on it the alpha of the symbol goes to 50%. This is exactly as expected.
4) I run the actionscript project with CheckoutButton.as
still in the classpath:
var x:CheckoutAnimation = new CheckoutAnimation();
addChild(x);
The checkout symbol appears in the animation, but clicking on it does nothing!!
WHY IS THIS! I DON'T UNDERSTAND! I don't understand why I don't get the same result as in (2) above, and I definitely don't understand why no code is executing. What is the conflict here?
This is a long shot, but based on the small bit of code you provided, it's the only thing that comes to mind. In your example, you've added x to the display list 4 times. It is possible that there are multiple instances of this symbol stacked on top of each other on the display list. When you set the alpha of any or all of them, you don't notice a change because you see the other symbols below it.
I understand that your code here might just be an example, but if you have added x to the display list 4 times then that's your problem. I've done this before, and it can go unnoticed until you start playing around with alphas or start moving objects around.
精彩评论