2 Replies Latest reply on Jul 16, 2009 11:00 AM by Gregory Lafrance

    drawRect

    rcanulla Level 1

      Hi there,

       

      I'm getting type conversion erros here in flex. Thoughts?

       

                private var _bg:Sprite;
                
                private function init():void {
                     
                     _bg = new Sprite;
                     _bg.graphics.beginFill(0x333333, 1);
                     _bg.graphics.drawRect(0,0,100,100);
                     _bg.graphics.endFill();
                     addChild(_bg);
      
      

       

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite@15845311 to mx.core.IUIComponent.
           at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:3259]
           at mx.core::Container/addChildAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2207]
           at mx.core::Container/addChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2140]
           at mediaTrapDesk/init()[/Users/Ryan/Documents/Flex Builder 3/mediaTrapDesk/src/mediaTrapDesk.mxml:55]
           at mediaTrapDesk/___mediaTrapDesk_WindowedApplication1_initialize()[/Users/Ryan/Documents/Flex Builder 3/mediaTrapDesk/src/mediaTrapDesk.mxml:8]
           at flash.events::EventDispatcher/dispatchEventFunction()
           at flash.events::EventDispatcher/dispatchEvent()
           at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
           at mx.core::UIComponent/set processedDescriptors()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1217]
           at mx.core::Container/createComponentsFromDescriptors()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:3506]
           at mx.core::Container/createChildren()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2589]
           at mx.core::WindowedApplication/createChildren()[C:\autobuild\3.2.0\frameworks\projects\airframework\src\mx\core\WindowedApplication.as:1766]
           at mx.core::UIComponent/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5370]
           at mx.core::Container/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2526]
           at mx.core::Application/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Application.as:846]
           at mediaTrapDesk/initialize()[/Users/Ryan/Documents/Flex Builder 3/mediaTrapDesk/src/mediaTrapDesk.mxml:0]
           at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2009]
           at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3234]
           at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3064]
           at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2916]
      
      
        • 1. Re: drawRect
          BennyBeta Level 4

          Try:


          _bg = new UIComponent();

           

          instead of:

           

          _bg = new Sprite();

           

          Let me know if that helps...

           

          Ben Edwards

          1 person found this helpful
          • 2. Re: drawRect
            Gregory Lafrance Level 6

            You can't add a Sprite to the display list. You need to wrap it in a UIComponent:

             

            private function init():void {
                _bg = new Sprite;
                _bg.graphics.beginFill(0x333333, 1);
                _bg.graphics.drawRect(0,0,100,100);
                _bg.graphics.endFill();

                var uic:UIComponent = new UIComponent();

                uic.addChild(_bg);
                addChild(uic);

            }

             

            If this post answered your question or helped, please mark it as such.