Using the ActionScript class (MovieClip) in flex

I have an ActionScript snippet that implements MovieClip. It seems I can’t display it in my application.

What I tried:
1) Using the class directly in my code through UIObject and Sprite. I can create a UIObject, add Sprite, and then add an instance of the class. Nothing is displayed in my application.

2) Putting the class in the flex library (swc). The compiler will not allow me to import it or use it as a display object.

3) Entering a class into a flex (swf) project. The file works fine, but gives me the same β€œbroken” icon when I try to use it in my application.

I am missing some key factor here. Suggestions?

EDIT: Got an add-in class to display through the library. It compiles to a .SWC file. Unfortunately, it uses the entire screen as "steps". The problem that I encountered when it was not visible was actually (or, I think) that it was on the right side of the display window. I set breakpoints in the drawing routines and saw that it was being updated. So now I'm trying to get him to take some measurements.

+4
source share
2 answers

You can create a UIComponent instead of a UIObject and add a movie clip to the UIComponent. I always used UIComponent instead of UIObject, and my sprite always displays correctly :) mxml and the code below:

<mx:UIComponent> <mx:Yoursprite></mx:Yoursprite> </mx:UIComponent> 

or encoded in actionscript:

 private function createSpriteInFlex():void { var _uiComponent:UIComponent = new UIComponent(); addElement(_uiComponent); var _sprite:YourSprite = new YourSprite(); _uiComponent.addChild(_sprite); } 

EDIT

You can just add the mxml line like this.

 <com:myUIComponent width="100%" height="100%"></com:myUIComponent> 

So, myUIComponent is actually a class that you can program yourself. I will demonstrate how you can add a sprite or movie clip below:

 package com.myUIComponent { public class myUIComponent extends UIComponent { public function myUIComponent() { super(); addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, init); //ADD YOUR SPRITE HERE var mySprite:YourSprite = new YourSprite(); addChild(mySprite); } } } 
+2
source

1) Using the class directly in my code through UIObject and Sprite. I can create a UIObject, add Sprite, and then add an instance of the class. Displays nothing in my application.

Did you give the clip and size of the move? (Width and height) and position (x and y)? Size is usually more important since x and y are often set to 0, 0.

 2) Putting the class in as a flex library (swc). The compiler won't let me import it or use it as a display object. 

Have you added SWC to your library path? Are you sure your new clip is included in SWC?

 3) Putting the class in as a flex project (swf). The file runs fine stand alone but gives me the same "broken" icon when I try to use it in my app. 

It looks like you have a problem with the attachment here; but you will have to show your code.

+2
source

All Articles