如何创建可在 Flex 和 Flash 中使用的超类?

发布于 2024-10-15 20:04:30 字数 977 浏览 6 评论 0原文

我正在开发一个使用 Flash Professional 和 Flash Builder 的项目。美术团队在 Flash Pro 中创建资源并将项目发布为 SWC。然后,我将 SWC 复制到 Flash Builder 项目的 lib 目录中,并通过该目录访问资源。

美术团队正在创作很多相同类型的东西;假设他们正在制作大量蜥蜴符号/组件。所有这些蜥蜴都有相似的动画(walk_left、walk_right 等),因此它们都具有在 ActionScript 中定义的与其动画中的关键帧相关的常量(WALK_RIGHT_START、WALK_RIGHT_END 等)。

从 Flex 方面来看,无论我加载哪个 Lizard,我都希望能够告诉它向左行走。因此,我在 Flash Professional 中创建了一个超类,现在 Flash Professional 中蜥蜴的所有 AS 类都扩展了该类 - Lizard.as

这一切都很好,但是当我想添加更多复杂性时对于我的蜥蜴来说,我不想打开 Flash Pro 项目、编辑类、重新编译 SWC、将其发送回 Flex,然后对其进行测试。我希望能够让我的 Lizard 超类可在 Flex 中进行编辑 - 因此我在 Flex 中创建了另一个超类:Lizard.mxml

在 Flex 中,每个蜥蜴组件(如 Gecko.mxml) strong>) 目前扩展了 Lizard.mxml,并且每个都包含 SWC 中定义的 AS 组件(在本例中为 Gecko.as)。

这看起来相当复杂:一个扩展 mxml 超类的 mxml 组件,包含一个扩展 AS 超类的 AS 组件。

我想要做的是在 Flex 项目中定义一个超类,让我的 Flash Pro 定义的组件扩展该类(这是我认为不可能的部分),然后让我的 Flex 组件 (Gecko.mxml) 扩展这些组件。

有什么办法可以做到这一点吗?

I am working on a project that is utilizing Flash Professional and Flash Builder. The art team creates assets in Flash Pro and publishes the project as a SWC. I then copy the SWC into my Flash Builder project's lib directory and access the assets through that.

The art team is creating a lot of the same type of thing; let's say they're making lots of lizard symbols/components. All of these lizards have similar animations (walk_left, walk_right, etc.) and because of this they all have constants defined in ActionScript (WALK_RIGHT_START, WALK_RIGHT_END, etc.) relating to the keyframes in their animations.

From the Flex side of things, whichever Lizard I load, I want to be able to tell it to walk left. So I created a superclass in Flash Professional and now all of the AS classes for the lizards in Flash Professional extend this class - Lizard.as

This is all fine and good, but when I want to add more complexities to my lizards, I don't want to have to open up the Flash Pro project, edit the class, recompile the SWC, send it back to Flex, and then test it out. I want to be able to have my Lizard superclass available for editing in Flex - so I made another superclass in Flex: Lizard.mxml

In Flex, each lizard component (like Gecko.mxml) currently extends Lizard.mxml, and each contains an AS component defined in the SWC (Gecko.as in this case).

This seems pretty convoluted: An mxml component extending an mxml superclass, containing an AS component which extends an AS superclass.

What I'd like to do is define one superclass in the Flex project, have my Flash Pro defined components extend this class (which is the part I believe to impossible), and then have my Flex Components (Gecko.mxml) extend those.

Is there any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-柠檬树下少年和吉他 2024-10-22 20:04:30

你不能改变一个类,你只能扩展它。

几年前,我正在开发一个项目,其中的界面是在 Flash 中完成并在 Flex 编译器中编译的。

我有不同的 ui 组件,由不同的类组成。但需要对我放入的逻辑进行相同的处理。这意味着所有类都必须具有相同的基类,而这必须是我自己的基类。因此按钮和列表都必须扩展自定义UIClass。据我所知,你不能这样做(如果你正在阅读本文并知道一种方法,请告诉我)

我的解决方案是创建一个包装器。

应用于您的问题时,会像这样

  • 创建一个名为 Lizard(或动物、有机体等)的“超类”,它扩展了 MovieClip(或 casaMovieClip)。
  • Lizard 将有一个变量 private var _view:MovieClip
  • 和一个初始化构造函数 'init($type:MovieClip)` (不是实际的构造函数)
  • ,其中 _view=$type 和你add view addChild(_view);

然后您将创建您的操作,就像

function walk():void{
   _view.gotoAndPlay("WALK");
} 

最后一件事是创建 Gecko 类,它将扩展 Lizard,并将其作为构造函数,

function Gecko(){
   init(new flaGecko());
}

然后如果您仍然需要重写您可以执行此操作的任何函数

,或者您可以只创建 var gecko:Lizard = new Lizard(new flaGecko()); 但随后您需要 init() 作为构造函数。

如需进一步阅读,请查阅装饰设计模式。我发现 AS3 设计模式书非常有帮助。

You can't change a class, you can only extend it.

Couple years ago I was working on a project where the interface was done in Flash and compiled in the flex compiler.

I had different ui components that consisted of different classes. But needed to treat them the same for the logic I was putting in. That meant all the classes had to have the same base class, which had to by my own base class. so a Button and a List both had to extend a customUIClass. Which as far as I know you cannot do (please let me know if you're reading this and know of a way)

my solution was to create a wrapper.

As applied to your issue would go something like this

  • make a "superclass" called Lizard(or animal,organism etc) that extends a MovieClip( or casaMovieClip).
  • Lizard would have a variable private var _view:MovieClip
  • and a init constructor 'init($type:MovieClip)` (not the actual constructor)
  • where _view=$type and you add view addChild(_view);

then you would create your actions like this

function walk():void{
   _view.gotoAndPlay("WALK");
} 

last thing would be to create the Gecko class, which would extend the Lizard, and would have this as constructor

function Gecko(){
   init(new flaGecko());
}

then if you still need to override any functions you can do that

or you could just create var gecko:Lizard = new Lizard(new flaGecko()); but then you would need the init() to be the constructor.

for further reading do look up the Decorator Design Pattern. I've found the AS3 design patterns book to be quite helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文