FlashBuilder编辑Flash IDE中定义的符号类

发布于 2025-01-07 07:36:15 字数 1189 浏览 2 评论 0原文

在 Flash IDE 中编码时,我经常使用以下过程来创建 MovieClip 类的专用版本:

我在 IDE 中设计我的对象,例如,我添加两个按钮并给它们实例名称“btn1”和“btn2” 。然后我将它们一起选择并将它们转换为符号。然后,我选择导出 ActionScript 并为其指定一个类名,假设为“MyClass”。

然后我去写一个专门的 MyClass.as ,如下所示:

public class MyClass extends MovieClip{
    private var _button1:Button;
    private var _button2:Button;

    public function MyClass(){
        this.addEventListener(Event.ADDED_TO_STAGE, init);
        ....
    }

    private function init(e:Event){
        _button1 = this["btn1"];
        _button2 = this["btn2"];
    }

    ...
}

(ps:我知道我不必将值分配给私有变量 _button1 和 _button2,而是可以直接调用 btn1,但我喜欢在我的代码中仅使用 Typesafe 变量)

这在 Flash IDE 中效果很好。当我创建 MyClass() 的新实例时,它将包含我在定义符号时在 Flash IDE 中定位的所有元素。这非常方便且直接。

现在我想在 FlashBuilder 中做同样的事情。

为此,我像以前一样在 Flash IDE 中设计了 MyClass 符号,为其指定了类名 MyClass,然后选择库符号并将其导出到 MyClass.SWC

在 Flash Builder 中,我将 MyClass.SWC 添加到构建路径,然后编写一个 MyClass.as与 Flash IDE 示例中的代码相同。但这一次,代码不起作用。 我会收到错误

_button1 = this["btn1"];

#1069,指出“btn1”未定义。

那么 - 如果使用 Flash Builder 进行开发,如何正确执行此操作?

PS:我在设置符号的类名时使用Flash IDE中的默认包,以及在FlashBuilder中设置as文件的默认包

谢谢!

When coding in the Flash IDE, i very often use the following procedure to create specialized versions of MovieClip classes:

I design my object in the IDE, for example, i add two buttons and give them the instance names "btn1" and "btn2". Then i select them together and convert them to a symbol. I then select Export for ActionScript and give them a classname, let's say "MyClass".

Then I go and write a specialized MyClass.as for it, like this:

public class MyClass extends MovieClip{
    private var _button1:Button;
    private var _button2:Button;

    public function MyClass(){
        this.addEventListener(Event.ADDED_TO_STAGE, init);
        ....
    }

    private function init(e:Event){
        _button1 = this["btn1"];
        _button2 = this["btn2"];
    }

    ...
}

(ps: i know that i wouldn't have to assign the values to the private variables _button1 and _button2 and instead could directly make calls to btn1, but I like to use only Typesafe variables in my code)

This works very well in Flash IDE. when I create a new instance of MyClass() it will contain all the elements that i positioned in the Flash IDE when defining the Symbol. This is very convenient and straight forward.

Now I want to do the same in FlashBuilder.

For this i designed the MyClass Symbol as before in Flash IDE, gave it the classname MyClass and then select the library symbol and export it to MyClass.SWC

In Flash Builder i add MyClass.SWC to the buildpath and I write a MyClass.as with the same code as in the Flash IDE example. but this time, the code won't work. on

_button1 = this["btn1"];

i will get an Error #1069 stating that "btn1" was not defined.

So - how to do this properly if developing with Flash Builder?

PS: i use the default package in Flash IDE when setting the Classname for the symbol as well as in FlashBuilder for the as file

Thanks!

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

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

发布评论

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

评论(2

小糖芽 2025-01-14 07:36:16

我是否可以建议您现在要转向 Flash Builder,稍微改变一下您的方法。虽然使用 SWC 没有任何问题,但您的资产是在编译时嵌入的,这意味着如果您更改它们,则需要重新编译应用程序。

我一直在使用一种方法,将影片剪辑放入 swf 中并加载它,然后为了保持您描述的类型安全,我使用 IMediaLibrary 方法。请参阅以下文章:

运行时类提取

这样做意味着您还可以与其他应用程序共享此 swf,它可能包含图标或您想要的任何内容,但我认为您会发现该方法非常灵活。

Might I suggest that now you are moving to Flash Builder that you change your approach slightly. Although there is nothing wrong with using a swc, your assets are embedded at compile time, which means you need to recompile your app if you change them.

I have been using an approach of putting movieclips in a swf and loading it in, and then to keep the type safety that you describe I use the IMediaLibrary approach. See the following article:

Runtime Class Extraction

Doing it this way means you can also share this swf with other applications, it may contain icons or whatever you want, but I think you will find the approach very flexible.

没企图 2025-01-14 07:36:16

您不需要使用 SWC(但您可以)。有一种方法可以让 flash Builder 和 flash IDE 很好地交织在一起用于项目,但您必须正确设置它。
在 flash IDE 中 - 转到编辑 -> 首选项 然后选择 actionscript。单击“actionscript 3 设置”并将源路径放置到包含您需要的所有 .as 文件的文件夹中。
然后在 flash builder 中转到项目 ->属性 单击“actionscript 构建路径”并转到“源路径”选项卡。这里选择您在 ide 中选择的相同文件夹(我的文件夹名为 lib)。现在回到 IDE 中,设置相对于您选择的文件夹的文档类。因此,如果您选择 lib,并且 lib 内部是文件夹 com、该电话内部以及 MainClass.as 内部,则在 IDE 基类中您将输入 com.phone.MainClass
现在,当您更改 flash 构建器代码并在 flash IDE 中进行编译时,它应该适合您:)

另外,这里有一种更简单(也许更清晰)的方法来访问库中的项目,

_phoneItselfClass = getDefinitionByName("PhoneItself") as Class;
_phoneItself:Sprite = new _phoneItselfClass() as Sprite;

这可能就像您的“主面板”。然后所有按钮都可以像这样访问:

_phoneItself["btn1"].addEventListener...
_phoneItself["btn2"].visible = true;

干杯,
吉姆

You don't need to use a swc (but you can). There is a way to have flash Builder and flash IDE nicely interwoven for a project, but you have to set it up correctly.
In flash IDE - go to edit->Prefrences Then choose actionscript. Click actionscript 3 settings and put the source path to the folder containing all the .as files you need.
Then in flash builder go to project -> properties Click actionscript build path and go to the tab for Source Path. Here choose the same folder that you chose in ide (my folder is named lib) Now back in IDE set your document class relative to the folder you chose. So if you chose lib, and inside of lib are the folders com, inside that phone, and inside that MainClass.as then in the IDE base class you would enter com.phone.MainClass
Now when you change flash builder code and compile in flash IDE it should work for you :)

Also, here is an easier (clearer, maybe) way to access items in your library

_phoneItselfClass = getDefinitionByName("PhoneItself") as Class;
_phoneItself:Sprite = new _phoneItselfClass() as Sprite;

This could be like your "main panel". Then all buttons could be accessed like this:

_phoneItself["btn1"].addEventListener....
_phoneItself["btn2"].visible = true;

Cheers,
Jim

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