添加外部 ActionScript 文件时自定义控件不显示
我遇到一个问题,我创建了一个自定义控件,当我将其添加到 FLA 文件中时,它会按我的预期显示。当我将 ActionScript (AS) 文件添加到自定义控件、重新加载组件列表并再次添加自定义控件时,它不再在我的 FLA 文件中显示自定义控件。
这是我所做的(也许我在这里做错了什么?):
- 创建一个新的 FLA 文件并将其命名为 Control1.fla
- 在舞台上创建一个矩形,右键单击它并选择“转换为符号”。
- 我将其命名为 Control1 并单击“确定”。
- 然后我右键单击库中的控件并选择“组件定义”。
- 我给它起了一个类名 Control1 并选中了“在组件面板中显示”复选框。
- 然后,我双击库中的 Control1 图标将其打开,并简单地添加了一行。
- 右键单击库中的 Control1 并选择“导出 SWC 文件...”并将其命名为 Control1.swc
- 然后我创建了一个新的 FLA 文件并将其命名为 Tester.fla
- 我刷新了组件列表(使用小下拉菜单组件列表标签的右侧)。
- 我将 Control1 控件放到舞台上,然后我看到我的控件以及我之前在其中绘制的线。
- 我运行该应用程序,并看到了我所期望的控件。
- 现在,我返回到 Control1.fla 文件并选择“文件/新建”,然后选择“ActionScript 3.0 Class”文件并输入 Control1 作为类名。将代码更改为:
package
{
import flash.display.MovieClip;
public class Control1 extends MovieClip {
public function Control1() {
// constructor code
}
}
}
- 我将此 AS 文件另存为 Control1.as
- 我返回到 Control1.fla 文件并右键单击库列表中的 Control1 图标并选择“导出 SWC 文件...”。
- 然后我返回到 Tester.fla 文件并删除舞台上的 Control1 对象。
- 我像在步骤 9 中一样刷新组件列表。
- 我将 Control1 组件拖到舞台上,并在出现的提示中选择“替换现有组件”,现在我在舞台上看到我的自定义控件。
- 但是,当我现在运行应用程序时,我看不到自定义控件 - 我只看到一个空白的白色舞台。
我很确定我错过了一个步骤或类似的东西 - 我刚刚开始学习 Flash 和 Flash。 AS3 和我遵循了这方面的教程,但我遇到了这个问题!
任何帮助将不胜感激! 谢谢!
I am having an issue where I have created a Custom Control and when I add it in a FLA file, it displays as I expect. When I add an ActionScript (AS) file to my custom control, reload the component list and add the custom control again, it no longer displays the custom control in my FLA file.
Here is what I did (maybe I did something wrong here?):
- Created a new FLA file and called it Control1.fla
- Created a rectangle on the stage and right clicked it and selected "Convert to Symbol".
- I gave it a name of Control1 and clicked OK.
- Then I right clicked on the control in the Library and selected "Component Definition".
- I gave it a class name of Control1 and checked the "Display in Components panel" checkbox.
- I then double clicked the Control1 icon in the Library to open it and simply added a line.
- Right click Control1 in the Library and select "Export SWC File..." and gave it a name of Control1.swc
- Then I created a new FLA file and called it Tester.fla
- I refreshed the Component list (using the little drop down to the right of the Components list label).
- I dropped the Control1 control onto the stage and I see my control with the line I drew earlier in it.
- I run the application and I see the control as I would expect.
- Now I go back to the Control1.fla file and select File / New and select "ActionScript 3.0 Class" file and enter Control1 as the class name. Change the code to be this:
package
{
import flash.display.MovieClip;
public class Control1 extends MovieClip {
public function Control1() {
// constructor code
}
}
}
- I save this AS file as Control1.as
- I go back to the Control1.fla file and right click on the Control1 icon in the Library list and select "Export SWC File...".
- I then go back to the Tester.fla file and delete the Control1 object I had on the stage.
- I refresh the Component list as I did in step 9.
- I drag the Control1 component onto the stage and select "Replace existing component" in the prompt that appears and I now see my custom control on the stage.
- However, when I run the application now, I do not see my custom control - I only see a blank white stage.
I am pretty sure I am missing a step or something like that - I am just starting to learn Flash & AS3 and I followed a tutorial on this, but I am running into this problem!
Any help would be greatly appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未制作过自定义 SWC 组件,但您遵循的过程很像制作自定义 FLA 组件。似乎缺少的步骤是将文件保存到 config/components 文件夹中。这是实现这一点的路径。
C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Components
然后重新启动闪存。 FLA 还要求您制作一个垫片,它只是一个编译的剪辑,其中包含您刚刚插入到库中的组件中的编译代码。我不确定 SWC 组件是否需要这样做。这是有关垫片和 fla 组件的链接,以防您需要或决定切换。
http://www.flexiblefactory.co.uk/flexible/?p=16
http://redbjarne.wordpress.com/actionscript-3-0-custom-components-from-hell/
这个对我帮助最大,但并不完美,请注意他的措辞。这可能很棘手。
I've never made a custom SWC component but the process you are following is a lot like making a custom FLA component. The step that seems to be missing is saving the file into the config/components folder. Here is the path for that.
C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Components
Then restart flash. FLA's also require you to make a shim, which is just a compiled clip that contains your compiled code that you just insert into your the component in your library. I'm not sure if SWC components require that. Here is a link about shims and fla components just in case you need it or decide to switch.
http://www.flexiblefactory.co.uk/flexible/?p=16
http://redbjarne.wordpress.com/actionscript-3-0-custom-components-from-hell/
This one helped me the most but it's not perfect and watch his phrasing. it can be tricky.