简体   繁体   English

在Actionscript代码中添加按钮:使用Flex Builder

[英]Adding button in Actionscript code : Using Flex Builder

I created a new actionscript project using Flex Builder 3 and tried 我使用Flex Builder 3创建了一个新的动作脚本项目,并尝试

to run the following file. 运行以下文件。 I get this error : 我收到此错误:

Definitions: fl.controls:Button could not be found. 定义:fl.controls:Button找不到。 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
            }
        }
    }

The fl.* package is part of Flash Professional, not Flex. fl。*软件包是Flash Professional而不是Flex的一部分。 For Flex you should be using the components that are part of the mx.* package. 对于Flex,您应该使用mx。*软件包中的组件。

Now, that being said, I'm fairly sure it is possible to use Flash components in Flex. 话虽如此,我很确定可以在Flex中使用Flash组件。 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. 另外,您不需要实际的按钮组件即可获得“按钮类似”的ui元素-扩展InteractiveObject的任何类都可以。 This incldes Sprite and MovieClip. 这包括Sprite和MovieClip。

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 布兰登是正确的,fl包是Flash IDE的一部分。我也不知道,但是如果您知道该包在文件系统上的位置,则可以将其添加到类路径中。在C:/程序文件/ adobe / flash中

if you want to use components in flex builder I think you need make a flex project not an actionscript project 如果您想在Flex Builder中使用组件,我想您需要制作一个Flex项目而不是一个ActionScript项目。

and change your imports to: 并将您的进口货更改为:

import mx.controls.Button;
import mx.controls.Label;
import mx.events.FlexEvent;

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. 同样,如果您不需要使用组件,则可以将Sprite用作branden所说的按钮,也可以只将TextField用作标签。

another option if you have the flash IDE is to make a SimpleButton, press F8 select button, click enter. 如果您具有Flash IDE,另一个选择是制作一个SimpleButton,按F8选择按钮,然后单击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: 然后导出.swf并将swf放入项目的src文件夹中,并将其嵌入如下:

[Embed(source="flashfile.swf")]
public var myButton:Class;

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. 您甚至可以通过这种方式导出Flash IDE组件,但不确定...实际上,如果[Embed]元数据可以在ActionScript项目中工作,或者只是在flex项目中工作,我并不是100%积极,因此您必须检查一下。

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 这取决于您拥有的IDE版本,对于CS4和Mac,位置为/ Applications / Adob​​e 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. 将那个文件夹或与您的安装/操作系统相关的文件夹添加到flashbuilder / eclipse中的类路径中,它将很好地解释类调用。

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. 如果您要编写纯动作脚本,不想使用flex组件,或者在IDE方法中采用混合编码和设计,这是很有意义的。

@philip the embed tag cannot be used in pure actionscript @philip embed标签不能在纯ActionScript中使用

不知道为什么要这么做,但是如果您需要将Flash库导入到flex中,请尝试将想要的内容拖到flash的舞台上,并导出为.swc文件以导入到Flex项目中。

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

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