简体   繁体   English

如何在Flash文件中使用FLEX 3组件?

[英]How about using FLEX 3 component inside Flash file?

Is it possible to use Flex 3 component/code inside Flash (cs4) SWF file ? 是否可以在Flash(cs4)SWF文件中使用Flex 3组件/代码?

I know its possible in the opposite direction. 我知道它有可能朝相反的方向发展。

I haven't used Flex code in a "pure AS3" project myself, but I don't see why you couldn't do that. 我自己没有在“纯AS3”项目中使用Flex代码,但是我不明白为什么您不能这样做。

You can download the Flex SDK and get the Flex components from there, both as an swc file (under /frameworks/libs ) and as AS3 source code (under /frameworks/projects/framework/src ). 您可以下载Flex SDK并从那里获取Flex组件,既可以是swc文件(在/frameworks/libs ),也可以是AS3源代码(在/frameworks/projects/framework/src )。

With my minimal testing it seems you can't use Flex components when building a "pure AS3" project. 通过我的最少测试,似乎在构建“纯AS3”项目时无法使用Flex组件。 (Can we start calling it PAS3 or something? Like "passé". Or "pastry". :) (我们可以开始称它为PAS3之类的吗?例如“passé”。还是“ pastry”。:)

I did this admittedly limited testing by creating a test project with one AS class as the "document class", which would instantiate and addChild one mx.controls.Button. 我通过创建一个具有一个AS类作为“文档类”的测试项目来进行有限的测试,该实例将实例化并添加一个mx.controls.Button子项。 I copied the whole mx package from the path mentioned by hasseg into the project source path. 我将整个mx包从hasseg提到的路径复制到了项目源路径。

This is what I found out: 这是我发现的:

  1. By removing the use of mx_internal from a certain Version.as file, I got Flash IDE to compile my test project without warning. 通过从某个Version.as文件中删除对mx_internal的使用,我获得了Flash IDE编译我的测试项目而没有警告。 Nothing showed up on the stage though. 舞台上什么也没出现。
  2. Using Flex Builder (and the flex compiler, obviously) I also managed to compile the project without errors. 使用Flex Builder(显然还有Flex编译器),我还成功地编译了项目,没有错误。 I put breakpoints in the code and watched it build itself in the debugger. 我在代码中放置了断点,并看着它在调试器中自行构建。 The components were instantiated flawlessly, but still nothing showed up on the stage. 完美地实例化了组件,但舞台上仍然没有任何显示。 This swf also crashed the browser numerous times. 该瑞士法郎还使浏览器崩溃了很多次。

In general you need to use MXML to initialise the Flex framework and use Flex components. 通常,您需要使用MXML初始化Flex框架并使用Flex组件。

Mike Chambers from Adobe says: Adobe的Mike Chambers说:

There is not support for using the Flex Framework in an AS only project. 不支持仅在AS项目中使用Flex Framework。 While it is theoretically possible, you would have to manually bootstrap a lot of the application initialization code that Flex handles (something which would be rather complex). 虽然从理论上讲是可行的,但您必须手动引导Flex处理的许多应用程序初始化代码(这会相当复杂)。 - Source - 来源

To see how complex, you can tell the compiler to keep the intermediate AS3 files that it generates from the MXML. 要了解其复杂程度,您可以告诉编译器保留从MXML生成的中间AS3文件。 Open your AS3 project properties and set -keep-generated-actionscript as an argument to the compiler. 打开AS3项目属性,并将-keep-generated-actionscript为编译器的参数。 Compile your project then look in the obj/generated folder. 编译项目,然后在obj / generated文件夹中查找。 Using Flex 4, I get 13 small files the main of which extends spark.components.Application and overrides a few methods. 使用Flex 4,我获得了13个小文件,它们的主要扩展了spark.components.Application并覆盖了一些方法。

So it's possible but you probably wouldn't want to do it. 因此有可能,但您可能不想这样做。 Flex is meant to make your life easier, not harder. Flex旨在使您的生活更轻松,而不是更艰难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM