如何在 Flash 中为 MovieClip 分配属性并在 Flex 中访问它们?

发布于 2024-10-19 14:42:22 字数 1650 浏览 1 评论 0原文

情况/问题

这是情况。

在 Flash Professional 中,我有一个 MovieClip,并且该剪辑有子级。假设父剪辑是夜空,子剪辑是循环动画的星星 MovieClip 的不同实例。整个内容编译为 NightSky.swc,我在 Flash Builder 中将其用作较大项目的一部分。

在 Flash Pro 中,我以高精度定位子剪辑。从那里,我想为这些“星星”分配属性。比如说,我想分配“galaxyId”和“isRedGiant”,但是(这是关键)我想在 Flash Professional 中编辑这些属性并在 Flex 中访问这些值。我该怎么做?

示例

例如,使用 Flash Pro,我在天空中放置了 6 颗星星,为它们全部指定了“MilkyWay”的星系 ID,并指定其中 3 颗为红巨星。然后,我编译 SWC 并移至 Flex。在 Flex (Flash Builder) 中,我有一些类似以下的逻辑:

public function showRedPulse():void {
    //psuedo-code just as an example:
    for each Child in the Night Sky
       if Child is in the Milky Way
           and if Child is a Red Giant
               Then, gotoAndPlay("redPulse")
}

所以基本上,我需要访问 Flex 中的属性,但需要在 Flash 中设置它们。

先前的解决方案

好的。我在 CS4 中已经这样做了大约 2 年,但在 CS5 中,它非常有问题。所以我正在寻找一种新方法。我之前所做的是创建一个 ActionScript 类(扩展 UIMovieClip)并将 Inspectable 元标记添加到我需要在 Flash 中看到的字段,如下所示:

private var _galaxyId:String;

[Inspectable(name="galaxyId", type=String, defaultValue="MilkyWay")]
public function set galaxyId(value:String):void {
     _galaxyId = value;
}

然后,在 flash professional 中,我会让“star”使用 actionscript 类作为它的基础班级。然后,我会右键单击库中的星号并编辑它的组件定义,将其指向同一个类。一旦我这样做了,所有可检查的属性都会显示在 Flash 的组件检查器中。

总结

我以前的方法多年来一直运行良好。现在,在 CS5 中,它的 bug 非常多,有时只能工作!我完全陷入困境,无法继续我的项目,并且我正在考虑完全放弃 Flash Pro 并尝试 Flash Catalyst。

我只需要在 Flash 中创建可以在 Flex(3.6 而非 Flex 4)中使用的对象。我需要这些 Flash 对象具有可以在 Flash 中编辑并在 Flex 代码中访问的属性。

我还能如何解决这个问题?这不应该那么难。

Situation / Question

Here's the situation.

In Flash Professional, I have a MovieClip and that clip has children. Let's say the parent clip is a night sky and the children are different instances of a star MovieClip that animates in a loop. This whole thing compiles down to a NightSky.swc which I use in Flash Builder as part of a larger project.

In Flash Pro, I position the child clips with a high level of precision. From there, I want to assign properties to these "stars." Say, I want to assign "galaxyId" and "isRedGiant" but (and this is key) I want to edit those properties in Flash Professional and have those value accessible in Flex. How do I do that?

Example

For example, using Flash Pro, I place 6 stars in the sky, give them all a galaxy ID of "MilkyWay" and designate 3 of them to be red giants. Then, I compile the SWC and move over to flex. In Flex (Flash Builder), I have some logic along the lines of:

public function showRedPulse():void {
    //psuedo-code just as an example:
    for each Child in the Night Sky
       if Child is in the Milky Way
           and if Child is a Red Giant
               Then, gotoAndPlay("redPulse")
}

So basically, I need to access the properties in Flex, but I need to set them in Flash.

Previous Solution

Ok. So I've done this for about 2 years now in CS4 but, in CS5, it's very buggy. So I'm looking for a new approach. What I did before was create an ActionScript Class (extending UIMovieClip) and add the Inspectable metatag to the fields I needed to see in Flash like this:

private var _galaxyId:String;

[Inspectable(name="galaxyId", type=String, defaultValue="MilkyWay")]
public function set galaxyId(value:String):void {
     _galaxyId = value;
}

Then, in flash professional, I would have the "star" use the actionscript class as it's base class. Then, I would right click on the star in the library and edit it's component definition, pointing it to the same class. Once I did that, all the inspectable properties would show up in Flash's Component Inspector.

Summary

My previous approach worked beautifully, for years. Now, in CS5, it's extremely buggy, working only sometimes! I'm completely stuck, can't move forward on my project, and I'm thinking of abandoning Flash Pro, entirely and trying Flash Catalyst, instead.

I just need to create Objects in Flash that I can use in Flex (3.6 not Flex 4). I need those Flash Objects to have properties that I can edit in Flash and access in Flex code.

How else can I approach this? This shouldn't be so hard.

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

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

发布评论

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

评论(2

—━☆沉默づ 2024-10-26 14:42:22

在元件属性中,为影片剪辑创建一个新类,然后在其中声明您的属性。只要您导入 SWC,Flex 就会看到该属性并且是类型安全的。

那里没有太多好的文档,这是我能找到的最好的文档:
http://www.adobe.com/devnet/flash/articles/concept_base_class.html

In the symbol properties, create a new class for the movieclip, then declare your property there. As long as you're importing the swc, Flex will see the property and be type-safe.

There isn't much good documentation out there, this is the best I could find:
http://www.adobe.com/devnet/flash/articles/concept_base_class.html

末骤雨初歇 2024-10-26 14:42:22

事实证明,CS5 中存在一个与使用组件相关的微妙错误。

Flash CS5 + components as children in UIMovieClips = fail.

保存为 CS4 文件时完全相同的文件可以零修改。

所以这个问题的“答案”是之前的解决方案是正确的方法。在 CS5 中解决这个奇怪的错误可能需要一些时间。据我所知,Adobe 已经意识到这个问题。

Turns out, there's a subtle bug in CS5 related to using components.

Flash CS5 + components as children in UIMovieClips = fail.

The exact same file when saved as a CS4 file works with zero modifications.

So the "answer" to this question is that the previous solution is the right way to do it. It just might take some time for this odd bug to get ironed out in CS5. As far as I know, Adobe is aware of the problem.

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