Class App extends Box

I hope this is the right forum for this, since this is a Flex/AS3 instead of a purely AS3 question. I couldn’t find a Flex/AS forum. Anyway,

I want to use ActionScript files with Flex, which works if I have as long as I don’t try to draw something, but as soon as I do… it gives me an error (below) Any ideas? I also tried to run the drawing script on Events.ADDED, but no go.

The reason why I want to use external AS is because I am using FlashDevelop for my authoring and it does not have code hinting when writing AS inside of the <mx:Script> tag.

(I just started learning Flex/AS3 over the weekend, quite a change from AS2 :slight_smile: )
Thank you in advance (again)


<?xml version="1.0" ?>
<!-- @mxmlc -output bin\App.swf -->
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:custom="*"
    width="100%" height="100%">
    <custom:App width="100%" height="100%" backgroundColor="0x00ff00" />
</mx:Application>


package {
    import flash.display.Sprite;
    import flash.events.Event;
    import mx.containers.Box;
    
    [SWF(width="800", height="600", frameRate="31", backgroundColor="#FFFFFF")]
    public class App extends Box {
        public function App() {
            var s:Sprite = new Sprite();
            s.graphics.lineStyle(2,0xff0000);
            s.graphics.drawRect(0,0,100,100);
            addChild(s);
            //addEventListener( Event.ADDED, init );
        }
    }
}

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite@1269c91 to mx.core.IUIComponent.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()
at mx.core::Container/addChildAt()
at mx.core::Container/addChild()
at App$iinit()
at mx.core::Container/createComponentFromDescriptor()
at mx.core::Container/createComponentsFromDescriptors()
at mx.core::Container/mx.core:Container::createChildren()
at mx.core::UIComponent/initialize()
at mx.core::Container/initialize()
at mx.core::Application/initialize()
at MindManager/initialize()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::docFrameHandler()