Unable to access Flash Component (SWC) in library in preview mode

I am creating a set of Flash components with the ability to replace the component skin with another in the library.

Currently, I can access the library after launching the application, but not during real-time preview, and I would like to know if it is possible for the component to access the library while working in real-time preview mode ( mode in which you can drag a component around the scene and change its properties in the "Component Settings" window)

Here is a simplified code that just looks to see if there is a symbol of the name specified and than instantiates it and adds it as a child.

 package { import fl.core.UIComponent; import flash.display.MovieClip; import flash.system.ApplicationDomain; /** * ... * @author Roy Lazarovich */ public class CompTest extends UIComponent { private var customfile :String; public function CompTest() { } override protected function configUI():void { } override protected function draw():void { super.draw(); } private function setCustomFile():void { if (ApplicationDomain.currentDomain.hasDefinition(customfile)) { var c:Class = Class(ApplicationDomain.currentDomain.getDefinition(customfile)); var mc:MovieClip = new c(); addChild(mc); } } [Inspectable(name = "_Custom File", defaultValue = "")] public function set _customfile(value:String):void { customfile = value; setCustomFile(); drawNow(); } } } 

code>

Thanks!

+6
source share
2 answers

I'm not quite sure that you have already tried to correct this situation. But hopefully this can help.

Right click on MovieClip in your library, select Linkage and give it a class name, i.e. MyThing.

In your code

 newMyThing = new MyThing(); this.addChild(newMyThing); trace("tada!"); 

Hope this helps or brings you closer to a solution.

0
source

This works for me in LivePreview if I apply it in configUI and don't draw:

 public class EditableBitmap extends UIComponent { protected var placeholder:String = "None"; protected var bitmap:Bitmap; protected var scale:Number = 1; [Inspectable(name = "Placeholder", type = String, defaultValue="None")] public function set Placeholder($value:String):void { placeholder = $value; configUI(); } public function get Placeholder():String { return placeholder; } public function EditableBitmap() { //Console.Debug("NEW EditableBitmap"); super(); } override protected function configUI():void { //Console.Debug("EditableBitmap configUI: " + width); if (!isNaN(width)) { wDim = width; hDim = height; graphics.clear(); graphics.beginFill(0x000000, 0.1); graphics.drawRect(0, 0, wDim, hDim); } if (placeholder != "None" && placeholder != "") { var asset:Class = getDefinitionByName(placeholder) as Class; var data:BitmapData = new asset() as BitmapData; bitmap = new Bitmap(data); } super.configUI(); } override protected function draw():void { if (bitmap) { addChild(bitmap); bitmap.x = off_x * scale; bitmap.y = off_y * scale; bitmap.scaleX = bitmap.scaleY = scale; } } } 

NOTE. . When I work on FLA, where I edit the component, the bitmap is displayed only from the library inconsistently. Sometimes it works, sometimes it doesn’t. But when I export SWC and then import the component into another movie, it works every time, both in LivePreview and at runtime.

UPDATE This does not seem to work in CS6 unless the character is already embedded in the .SWC component. I wanted to see if I could fool him by inserting one image into SWC, and then replacing it with a different name in the destination file. This did not work, but it reminded me of how you can do this:

enter image description here

So this is a bit complicated, but you can get around this:

1) Create a dummy asset for each property in the SWC component. 2) Overriding this using a custom class in the file where you deploy the component

... all this may be more of a problem than it is worth, but which should provide a solution to the problem.

0
source

Source: https://habr.com/ru/post/919663/


All Articles