ActionScript 项目中的类如何覆盖 Flash CS3 SWC 文件中的类?
我有一个动作脚本项目,它使用 SWC 中的视觉符号。
我有一个 CheckoutButton
,它具有与其关联的以下类(编译到 Flash CS3 中的 SWC 中)。
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 {
}
}
重要提示:CheckoutButton.as
文件位于使用 SWC 的 ActionScript 项目的类路径中。
我在 ActionScript 项目中使用编译后的 SWC,并且运行了以下场景:
1) 我从 ActionScript 项目的类路径中删除了 CheckoutButton.as
:
var x:CheckoutButton = new CheckoutButton();
addChild(x);
我从 Flash 中获取了视觉符号的实例CS3 文件。当我点击它时,它的 alpha 变为 50%。这又完全符合我的预期。
2)我在我的actionscript项目的类路径中使用CheckoutButton.as
运行此代码:
var x:CheckoutButton = new CheckoutButton();
addChild(x);
什么也没有发生。这正是我所期望的 - 因为我基本上已经使用没有任何可视功能的 SimpleButton
覆盖了 SWC 中的类定义。
现在,我的 Flash 文件中还有一个时间线动画 CheckoutAnimation
,它恰好包含 CheckoutButton
符号的实例。
3)我在从类路径中删除 CheckoutButton.as
后运行actionscript项目:
var x:CheckoutAnimation = new CheckoutAnimation();
addChild(x);
动画中的符号拾取类定义(最初编译到SWC中),当我单击它时,符号变为 50%。这完全符合预期。
4) 我运行actionscript 项目,CheckoutButton.as
仍在类路径中:
var x:CheckoutAnimation = new CheckoutAnimation();
addChild(x);
结帐符号出现在动画中,但单击它没有任何反应!
这是为什么!我不明白!我不明白为什么我没有得到与上面(2)相同的结果,而且我绝对不明白为什么没有代码正在执行。这里有什么冲突呢?
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 CheckoutAnimation
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个不太可能的事情,但根据您提供的一小段代码,这是我唯一想到的事情。在您的示例中,您已将 x 添加到显示列表 4 次。显示列表上可能有多个此符号的实例堆叠在一起。当您设置其中任何一个或全部的 Alpha 时,您不会注意到任何变化,因为您会看到其下方的其他符号。
我知道您这里的代码可能只是一个示例,但如果您已将 x 添加到显示列表 4 次,那么这就是您的问题。我以前已经这样做过,并且在您开始使用 Alpha 或开始移动对象之前,它可能不会被注意到。
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.