2 Replies Latest reply on Jul 20, 2006 10:48 AM by Newsgroup_User

    When a warning is really an error....

    Level 7
      I tested the following component out in the Flash 9 pre-release. Now I am
      trying it in Flex 2.

      But I get the following error (actually it calls it a warning, but it seems
      to be an error, since the custom component is not made, and the text of the
      warning says error).

      Design mode: Error creating item BasicSprite in parent Application.


      The MXML file is

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      xmlns:ktg="ktg.Basics.*">
      <ktg:BasicSprite />
      </mx:Application>


      The BasicSprite.as file (which is in the ktg/Basics/ subdirectory)

      package ktg.Basics
      {
      import flash.display.*;
      import flash.events.*;
      import flash.text.TextField;
      import mx.containers.*

      public class BasicSprite extends HBox
      {
      private var textBox:TextField;

      public function BasicSprite()
      {
      textBox = new TextField();
      textBox.text = "Welcome to KTG";
      addChild(textBox);
      }

      public function setText(newText:String) : void
      {
      textBox.text = newText;
      }
      }
      }



        • 1. Re: When a warning is really an error....
          Level 7
          The problem is that your AS class is trying to add a Flash TextField as
          a child of a Flex HBox. Flex containers expect their children to be
          other Flex components, and not Flash display objects.

          The specific error is that the call to addChild(textBox) is throwing an
          exception because it expects a parameter of type UIComponent, and
          textBox is a TextField which does not inherit from UIComponent.

          If you compile and run the swf file generated by your application in the
          stand-alone Flash player, you will see this exception and a stack trace.

          The solution is to use a Flex component rather than TextField to draw
          the text. For example, TextArea or Label (depending on whether you want
          multiline or single line text.

          A version of BasicSprite.as that works is:

          package ktg.Basics
          {
          import flash.display.*;
          import flash.events.*;
          import flash.text.TextField;
          import mx.containers.*

          import mx.controls.TextArea;

          public class BasicSprite extends HBox
          {
          private var textBox:TextArea;

          public function BasicSprite()
          {
          textBox = new TextArea();
          textBox.text = "Welcome to KTG";
          addChild(textBox);
          }

          public function setText(newText:String) : void
          {
          textBox.text = newText;
          }
          }
          }


          -- Greg Dow
          -- Adobe Flex Builder Team

          Yechezkal Gutfreund wrote:
          > I tested the following component out in the Flash 9 pre-release. Now I am
          > trying it in Flex 2.
          >
          > But I get the following error (actually it calls it a warning, but it seems
          > to be an error, since the custom component is not made, and the text of the
          > warning says error).
          >
          > Design mode: Error creating item BasicSprite in parent Application.
          >
          >
          > The MXML file is
          >
          > <?xml version="1.0" encoding="utf-8"?>
          > <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
          > xmlns:ktg="ktg.Basics.*">
          > <ktg:BasicSprite />
          > </mx:Application>
          >
          >
          > The BasicSprite.as file (which is in the ktg/Basics/ subdirectory)
          >
          > package ktg.Basics
          > {
          > import flash.display.*;
          > import flash.events.*;
          > import flash.text.TextField;
          > import mx.containers.*
          >
          > public class BasicSprite extends HBox
          > {
          > private var textBox:TextField;
          >
          > public function BasicSprite()
          > {
          > textBox = new TextField();
          > textBox.text = "Welcome to KTG";
          > addChild(textBox);
          > }
          >
          > public function setText(newText:String) : void
          > {
          > textBox.text = newText;
          > }
          > }
          > }
          >
          >
          >
          • 2. Re: When a warning is really an error....
            Level 7
            Thank you Greg,


            "Gregory Dow" <ghd@aol.com> wrote in message
            news:e9ofjh$pb2$1@forums.macromedia.com...
            > The problem is that your AS class is trying to add a Flash TextField as a
            > child of a Flex HBox. Flex containers expect their children to be other
            > Flex components, and not Flash display objects.
            >
            > The specific error is that the call to addChild(textBox) is throwing an
            > exception because it expects a parameter of type UIComponent, and textBox
            > is a TextField which does not inherit from UIComponent.
            >
            > If you compile and run the swf file generated by your application in the
            > stand-alone Flash player, you will see this exception and a stack trace.
            >
            > The solution is to use a Flex component rather than TextField to draw the
            > text. For example, TextArea or Label (depending on whether you want
            > multiline or single line text.
            >
            > A version of BasicSprite.as that works is:
            >
            > package ktg.Basics
            > {
            > import flash.display.*;
            > import flash.events.*;
            > import flash.text.TextField;
            > import mx.containers.*
            >
            > import mx.controls.TextArea;
            >
            > public class BasicSprite extends HBox
            > {
            > private var textBox:TextArea;
            >
            > public function BasicSprite()
            > {
            > textBox = new TextArea();
            > textBox.text = "Welcome to KTG";
            > addChild(textBox);
            > }
            >
            > public function setText(newText:String) : void
            > {
            > textBox.text = newText;
            > }
            > }
            > }
            >
            >
            > -- Greg Dow
            > -- Adobe Flex Builder Team
            >
            > Yechezkal Gutfreund wrote:
            >> I tested the following component out in the Flash 9 pre-release. Now I am
            >> trying it in Flex 2.
            >>
            >> But I get the following error (actually it calls it a warning, but it
            >> seems
            >> to be an error, since the custom component is not made, and the text of
            >> the
            >> warning says error).
            >>
            >> Design mode: Error creating item BasicSprite in parent Application.
            >>
            >>
            >> The MXML file is
            >>
            >> <?xml version="1.0" encoding="utf-8"?>
            >> <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
            >> layout="absolute"
            >> xmlns:ktg="ktg.Basics.*">
            >> <ktg:BasicSprite />
            >> </mx:Application>
            >>
            >>
            >> The BasicSprite.as file (which is in the ktg/Basics/ subdirectory)
            >>
            >> package ktg.Basics
            >> {
            >> import flash.display.*;
            >> import flash.events.*;
            >> import flash.text.TextField;
            >> import mx.containers.*
            >>
            >> public class BasicSprite extends HBox
            >> {
            >> private var textBox:TextField;
            >>
            >> public function BasicSprite()
            >> {
            >> textBox = new TextField();
            >> textBox.text = "Welcome to KTG";
            >> addChild(textBox);
            >> }
            >>
            >> public function setText(newText:String) : void
            >> {
            >> textBox.text = newText;
            >> }
            >> }
            >> }
            >>
            >>