4

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 as 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.

ethrbunny
  • 10,379
  • 9
  • 69
  • 131

2 Answers2

2

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.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • MovieClip has size and position. When added from an external file (be it SWF or SWC) I see it positioned but it won't draw. – ethrbunny Jun 14 '11 at 19:02
  • @ethrbunny Please show your code for "adding it". Are you embedding it? Or using a SWFLoader? Or something else? – JeffryHouser Jun 14 '11 at 20:01
2

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);
        }
    }
}
Michiel Standaert
  • 4,096
  • 7
  • 27
  • 49
  • Tried this as part of using the class locally. Added a UIComponent to my page, then added the Sprite and finally the MovieClip. Appeared to go in ok but nothing displayed. – ethrbunny Jun 14 '11 at 19:01
  • I had assumed--perhaps incorrectly that his reference to UIObject was a typo for UIComponent; based on a quick search, UIObject was part of Flex 1.5; but no links show up for Flex 2 or greater. – JeffryHouser Jun 14 '11 at 20:00
  • Normally, this should work. Have you tried the coded approach or the mxml-approach? I will update my post with another (coded) example. – Michiel Standaert Jun 15 '11 at 08:56