在 flash 中编译一个 swc 以在 flex 中使用,用 flex 编写一个类 [英] compile a swc in flash for use in flex, with a class written in flex

查看:23
本文介绍了在 flash 中编译一个 swc 以在 flex 中使用,用 flex 编写一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,

听起来很复杂,其实不然.开始:我想使用一些资产(按钮等),我在 flex actionscript 项目中的 flash 中创建.由于我所有的资产都低于 10K,我不打算加载 swf,等到它加载并创建界面.我想使用 swc 并仅实例化我需要的剪辑.另外,我希望我的 Button 类有一些额外的属性,这就是问题发生的地方.

It sounds complicated, but it's not. Here goes: I want to use some assets ( buttons, etc. ) I'm creating in flash in a flex actionscript project. Since all my assets are bellow 10K, I'm not planning to load a swf ,wait until it's loaded and create the interface. I want to use a swc and just instance the clips I need. Also, I want my Button class to have some extra properties, and this is where the problem occurs.

如果在 Flash IDE 的链接属性中添加对自定义 Button 类的引用并跟踪 Button MovieClip 的子项,我会得到正确的跟踪.如果然后我在 Flex 的 Main 类中创建一个 Button,使用生成的 swc 文件并跟踪 Button MovieClip 的同一个子项,我会得到 null.

If in the Linkage Properties in the Flash IDE I add a reference to a custom Button Class and trace a child of the Button MovieClip, I get the right trace. If then I create a Button, in the Main class in Flex, using the generated swc file and trace the same child of the Button MovieClip, I get null.

这是为什么?有没有办法解决这个问题?我曾考虑使用 Flex Component Kit,但由于我正在处理一个简单的 actionscript 项目并且我没有使用 Flex 框架,因此我认为此时使用 Component Kit 没有意义.

Why is that ? Is there anyway to get around this ? I've considered using the Flex Component Kit, but since I'm working on a simple actionscript project and I'm not using the Flex framework, I see no point in using the Component Kit at this point.

谢谢!

推荐答案

我想我明白了.

我的 Button MovieClip 与 Flex actionscript 项目中我的 actionscript 代码的其余部分链接到同一 src 文件夹中的一个类.(as3 类路径设置为../",来自 .fla 文件所在的资产文件夹,上一级 src )

My Button MovieClip was linking to a class in the the same src folder as the rest of my actionscript code in the Flex actionscript project. (The as3 classpath was set to "../", from the assets folder where the .fla file lives, one level up to src )

当 Flash 编译时,找到了类并且我进入了 .swc 文件.这就是为什么我从 flash 中跟踪符号的原因.Flex 编译时,在 src 目录中找到了该类,因此编译了同一类的新版本,尽管它已经存在于 swc 文件中.由于 flex 找到了 .as 文件,但不知道我将它链接到 Flash IDE 中的一个符号(我认为它不能这样做),Flex 创建了它的类版本,但由于没有链接符号到那个班级,我正在追踪的 Button 的孩子是空的.

When Flash compiled, the class was found and I got in the .swc file. That is why I got the symbol traced from flash. When Flex compiled, the class was found in the src directory, so a new version of the same class was compiled, although it already existed in the swc file. Since flex found the .as file, but wouldn't know I had it linked to a symbol in the Flash IDE ( I don't think it can do that ), Flex created its version of the class, but since no symbol was linked to that class, the child of Button I was tracing was null.

我想使用包并保持 fla 链接的类分开,这样 Flex 就不会编译同一个类两次.

I guess using packages and keeping the fla linked classes separate so Flex wouldn't compile the same class twice.

奇怪的是我没有收到任何警告或错误,所以我认为一切都很好.

The weird thing is I didn't get any warning or error, so I assumed everything was fine.

一个快速且不那么脏的解决方法是从文件系统中删除物理 Button 类,以便 Flash 可以在编译时生成它的版本并引用 Button 符号的子代.然后在 Flex 中,我创建了一个扩展 Button 的类并添加了我需要的代码.由于生成的类是在 .swc 文件中编译的,因此 Flex 可以看到,并且我在扩展时没有问题.

A quick and not so dirty workaround was to delete the physical Button class from the filesystem, so that Flash could generate it's version on compile time and have references to the children of the Button symbol. Then in Flex I cread a class that extends Button and added the code I needed. Since the generated class got compiled in the .swc file, Flex could see that and I had no problem extending.

就是这样!鲍勃是你的叔叔!

That was it! Bob's you're uncle!

我假设会发生什么,我不是 100% 确定.这是我的直觉通过观察认为理所当然的事情,所以我可能在技术上是错误的.如果有人有任何更正,欢迎他们.

I assumes that what happens, I am not 100% sure. It's something my intuition takes for granted through observation, so I might be technically wrong. If anyone has any correction they're welcome.

这篇关于在 flash 中编译一个 swc 以在 flex 中使用,用 flex 编写一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆