2 Replies Latest reply on Jun 25, 2009 8:48 PM by rcanulla

    Touble adding class to stage

    rcanulla Level 1

      Hi there,

       

      I have a view class that is extended by the NewsView class. I add a vBox and Text field to the stage in here, and then add the NewsView to the stage in my main application. When I do so, I get an UI error.. Thoughs?

       

      View.as

      package com.ryancanulla.mvc
      {
           import flash.display.Sprite;
           import flash.events.Event;
          
           public class View extends Sprite
           {
                private var _model:Model
          
                public function View()
                {
                }
                public function update(e:Event = null):void {
                   & nbsp;
                }
                public function set model(m:Model):void {
                   & nbsp; _model = m;
                   & nbsp; _model.addEventListener(Model.MODEL_CHANGE, update);
                }
                public function get model():* {
                   & nbsp; return _model;
                }

           }
      }

       

      NewsView.as

       

      package com.ryancanulla.mvc
      {
           import mx.containers.VBox;
           import mx.controls.Text;
          
           public class NewsView extends View {
                public var container:VBox;
                private var _itemInfo:Text;
               
                public function NewsView() {
                   & nbsp; trace("View Instantiated");
                   & nbsp; container = new VBox();
                   & nbsp; _itemInfo = new Text();
                   & nbsp; _itemInfo.text = "this is a test";
                   & nbsp; //container.addChild(_itemInfo);
                   & nbsp; //addChild(container);
                }

           }
      }

       

      Where I add to myText (VBOX)

       

                   &n bsp; 
                   & nbsp; _newsView = new NewsView();
                   & nbsp; myTest.addChild(_newsView);
                   & nbsp;
                }

       

      error

      TypeError: Error #1034: Type Coercion failed: cannot convert com.ryancanulla.mvc::NewsView@18df7c41 to mx.core.IUIComponent.
           at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()[C:\autobuild\3.2.0\framewor ks\projects\framework\src\mx\core\Container.as:3259]
           at mx.core::Container/addChildAt()[C:\autobuild\3.2.0\frameworks\projects\framewor k\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:34]
           at mediaTrapDesk/___mediaTrapDesk_WindowedApplication1_creationComplete()[/Users/R yan/Documents/Flex Builder 3/mediaTrapDesk/src/mediaTrapDesk.mxml:11]
           at flash.events::EventDispatcher/dispatchEventFunction()
           at flash.events::EventDispatcher/dispatchEvent()
           at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\fra mework\src\mx\core\UIComponent.as:9298]
           at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UICo mponent.as:1169]
           at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\framework s\projects\framework\src\mx\managers\LayoutManager.as:718]
           at Function/http://adobe.com/AS3/2006/builtin::apply()
           at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\proje cts\framework\src\mx\core\UIComponent.as:8628]
           at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projec ts\framework\src\mx\core\UIComponent.as:8568]