在 Actionscript 代码中添加按钮:使用 Flex Builder
我使用 Flex Builder 3 创建了一个新的 ActionScript 项目,并尝试
运行以下文件。 我收到此错误:
定义:fl.controls:无法找到按钮。 我想做的就是向应用程序添加一个按钮。 我怎样才能做到呢?
package {
import PaperBase;
import org.papervision3d.objects.primitives.Cone;
import fl.controls.Button;
import fl.controls.Label;
import fl.events.ComponentEvent;
public class cone1 extends PaperBase {
public var cone:Cone = new Cone();
protected var sceneWidth:Number;
protected var sceneHeight:Number;
public function cone1() {
sceneWidth = stage.stageWidth
sceneHeight = stage.stageHeight;
init(sceneWidth*0.5,sceneHeight*0.5);//position of the cone
}
override protected function init3d():void {
cone.scale = 5;
cone.pitch(-40)
default_scene.addChild(cone);
}
override protected function processFrame():void {
cone.yaw(1);//rotation speed
}
}
}
I created a new actionscript project using Flex Builder 3 and tried
to run the following file. I get this error :
Definitions: fl.controls:Button could not be found.
All I want to do is, to add a button to the application.
How could I do it?
package {
import PaperBase;
import org.papervision3d.objects.primitives.Cone;
import fl.controls.Button;
import fl.controls.Label;
import fl.events.ComponentEvent;
public class cone1 extends PaperBase {
public var cone:Cone = new Cone();
protected var sceneWidth:Number;
protected var sceneHeight:Number;
public function cone1() {
sceneWidth = stage.stageWidth
sceneHeight = stage.stageHeight;
init(sceneWidth*0.5,sceneHeight*0.5);//position of the cone
}
override protected function init3d():void {
cone.scale = 5;
cone.pitch(-40)
default_scene.addChild(cone);
}
override protected function processFrame():void {
cone.yaw(1);//rotation speed
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
fl.* 包是 Flash Professional 的一部分,而不是 Flex 的一部分。 对于 Flex,您应该使用 mx.* 包中的组件。
话虽这么说,我相当确定可以在 Flex 中使用 Flash 组件。 我只是不确定它是如何从我的脑海中完成的。
另外,您不需要实际的按钮组件来获取“类似按钮”的 ui 元素 - 任何扩展 InteractiveObject 的类都可以。 这包括 Sprite 和 MovieClip。
The fl.* package is part of Flash Professional, not Flex. For Flex you should be using the components that are part of the mx.* package.
Now, that being said, I'm fairly sure it is possible to use Flash components in Flex. I'm just not sure how it's done off the top of my head.
Also, you don't need an actual button component to get a "button like" ui element - any class that extends InteractiveObject will do. This incldes Sprite and MovieClip.
Branden 是正确的,fl 包是 Flash IDE 的一部分。我也不确定,但如果您知道该包驻留在文件系统上的位置,您也许可以将该包添加到您的类路径中。我猜测在某个地方在 C:/program files/adobe/flash 中,
如果您想在 Flex 构建器中使用组件,我认为您需要创建一个 Flex 项目而不是 ActionScript 项目
,并将导入更改为:
另外,如果您不需要使用组件,您也可以使用像布兰登所说的按钮的精灵,你可以只使用文本字段作为标签。
如果您有 flash IDE,另一个选择是制作一个 SimpleButton,按 F8 选择按钮,单击 Enter。 然后通过在库面板中右键单击并选择链接名称为其指定链接名称。 然后导出 .swf 并将 swf 放入项目的 src 文件夹中,然后像这样嵌入:
您甚至可以通过这种方式导出 Flash IDE 组件,但不确定...实际上,如果[嵌入] 元数据适用于 ActionScript 项目或 Flex 项目,因此您必须检查并查看。
Branden is correct the fl package is a part of the Flash IDE..I am not sure either but you may be able to add the package to your class path if you know where the package resides on your file system..i am guessing somewhere in C:/program files/adobe/flash
if you want to use components in flex builder I think you need make a flex project not an actionscript project
and change your imports to:
Also if you do not need to use components either you can use a Sprite for a button like branden said and you could just use a TextField for a label.
another option if you have the flash IDE is to make a SimpleButton, press F8 select button, click enter. then give it a linkage name by right clickin it in the library panel and selecting linkage name. then export the .swf and put the swf in the src folder for your project and embed it like this:
You may even be able to export the Flash IDE components this way but not sure...actually I am not 100% positive if the [Embed] meta data works in an actionscript project or just flex projects so you will have to check and see.
这取决于您拥有的 IDE 版本,对于 CS4 和 Mac,位置为 /Applications/Adobe Flash CS4/Common/First Run/Classes
将该文件夹或您的安装/操作系统的相关文件夹添加到 flashbuilder/eclipse 中的类路径中它会很好地解释类调用。
如果您正在编写纯动作脚本并且不想使用 Flex 组件,或者在 IDE 方法中采用混合编码和设计,那么这是有意义的。
@philip 嵌入标签不能在纯动作脚本中使用
It depends what version of the IDE you have, for CS4 and Mac the location would be /Applications/Adobe Flash CS4/Common/First Run/Classes
Add that folder or the relevant folder for your installation/OS to your classpath in flashbuilder/eclipse and it will interpret the class calls fine.
It makes sense if you're coding pure actionscript and dont want to use flex components, or employing a mixed coding and designing in IDE approach.
@philip the embed tag cannot be used in pure actionscript
不知道为什么你想要这样做,但如果你需要将 flash 库导入到 Flex 中,请尝试将你想要的内容拖到 Flash 中的舞台上,然后导出为 .swc 文件以导入到你的 Flex 项目中。
Not sure why you would want to, but if you need to import the flash libs into flex,try dragging what you want to the stage in flash and exporting as a .swc file to import into your flex project.