简体   繁体   中英

how to share a component in as3

I have a custom component(eg. MyButton) used in several swfs. I'd like to share the component in runtime, thus once our designer change the button's visual effect, we need not publish all flas that uses this button.

In as2, I can put this button in an asset fla(eg. lib.swf) and check the "export for runtime share" in symbol property. Then copy the button to a fla(eg. main.swf) and check the "import for runtime share", this works fine. However in as3, after doing above, if I put a button instance on stage and modify its inspectable property, i'll get a compile error "1046:Type was not found or was not a compile-time constant".

I searched the web and found this http://www.kirupa.com/forum/showthread.php?317257-Runtime-Shared-Library-woes . Then I tried the swc approach, but it seems swc will be compiled into swf, it doesn't share at all.

  1. the shared component must be put on the stage , because all fla will be modified by our designer while he knows nothing about programing.
  2. we can not use flex , all operation must be done in Flash CS5.

1: Placed on Library all of your components to .fla as follows: my fla names BrushClip.fla the components wrapped a MovieClip . and be ActionScript Linking export to ActionScript Class.

在此处输入图片说明

2: File - Publish Settings check SWC format and publish as follows:

在此处输入图片说明

3: check, created swc file in your project. now you can using a swc other project you must linking to SWC library in File-ActionScript Settings-Library Path. and later if you change a components design, re-publish. and copy and paste swc file. automatically will change restart swf file. BrushClip.swc has a all components.

在此处输入图片说明

you can access as follows:

var brushClip0:MovieClip = new BrushClip0();
addChild(brushClip0);

var brushClip10:MovieClip = new BrushClip10();
addChild(brushClip10);

I've found the solution.

  1. Give the Sprite that holds the imported components a binding class
  2. Edit the class file, declare the components yourself regardless of whether checked the "auto declare instance on stage"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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