Using Actionscript (MovieClip) class in flex
I have a piece of Actionscript code that Implements MovieClip. I don't seem to be able to get it to display in my application.
What I've tried:
1) Using the class directly in my code via UIObject and Sprite. I can create the UIObject, add the Sprite and then add an instance of the class. Nothing displays in my app.2) Putting the class in as a flex library (swc). The compiler won't let me import it or use it 开发者_如何学Cas a display object.
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.
Im missing some key factor here. Suggestions?
EDIT: Got the add-in class to display via a library. It compiles to a .SWC file. Unfortunately it's using the full screen as its 'stage' dimensions. The issue I was having before with it not being visible was actually (or so I think) that it was off the right side of the display window. I put break points in the drawing routines and could see that it was being refreshed. So now Im trying to get it to accept some dimensions.
You can create a UIComponent instead of UIObject and add the movieclip to the UIComponent. I have always used UIComponent instead of UIObject and my sprite is always displayed correctly :) mxml and code below:
<mx:UIComponent>
<mx:Yoursprite></mx:Yoursprite>
</mx:UIComponent>
or coded 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 an mxml line like this.
<com:myUIComponent width="100%" height="100%"></com:myUIComponent>
So the myUIComponent is actually a class that you can code yourself. I will demonstrate how you can add a sprite or movieclip 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);
}
}
}
1) Using the class directly in my code via UIObject and Sprite. I can create the UIObject, add the Sprite and then add an instance of the class. Nothing displays in my app.
Did you give the move clip and size? ( Width and height) and position (x and y)? The size is usually more important because 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.
did you add the SWC to your library path? Are you sure your new movie clip is included in the 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 sounds like you have a path issue w/ embedding here; but you'd have to show your code.
精彩评论