1 Reply Latest reply on May 12, 2006 5:05 PM by Newsgroup_User

    Nested classes?

    McRib64
      Hi
      I'm following the blog reader example in the 2nd chapter of the 'Developing Rich Clients with Macromedia Flex' book, but using Flex Beta 2.

      I've got a class called BlogViewHelper defined in a file called BlogViewHelper.as, and I've got <mx:Script source="BlogViewHelper.as" /> in my main mxml document. However, I've got this error on the first line of my actionscript file-

      'classes must not be nested'.

      I really haven't been about to get around this error. Obviously I'm pretty new to actionscript and flex, but I'm giving it a go the practical way. If anyone could lend a hand in sorting out this error, I would be grateful.
        • 1. Re: Nested classes?
          Level 7
          There is no need to use <mx:Script source="BlogViewHelper.as" />. Both
          BlogViewHelper and your main mxml document are both classes. You should be
          able to access the BlogViewHelper class from your main mxml application.
          Just instantiate an instance of it and use it like any other object.

          Quick example:

          classAccess.mxml:

          <?xml version="1.0" encoding="iso-8859-1" ?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="mc =
          new MyClass()">

          <mx:Script>
          public var mc:MyClass;


          </mx:Script>

          <mx:Button label="Run" click="mc.doTrace('yup, it worked')"/>

          </mx:Application>

          MyClass.as:

          package
          {
          public class MyClass extends Object
          {
          public function MyClass()
          {
          }

          public function doTrace(value:String):void
          {
          trace(value);
          }
          }
          }



          Jason Szeto


          "McRib64" <webforumsuser@macromedia.com> wrote in message
          news:e3698b$d7t$1@forums.macromedia.com...
          > Hi
          > I'm following the blog reader example in the 2nd chapter of the
          > 'Developing
          > Rich Clients with Macromedia Flex' book, but using Flex Beta 2.
          >
          > I've got a class called BlogViewHelper defined in a file called
          > BlogViewHelper.as, and I've got <mx:Script source="BlogViewHelper.as" />
          > in my
          > main mxml document. However, I've got this error on the first line of my
          > actionscript file-
          >
          > 'classes must not be nested'.
          >
          > I really haven't been about to get around this error. Obviously I'm pretty
          > new
          > to actionscript and flex, but I'm giving it a go the practical way. If
          > anyone
          > could lend a hand in sorting out this error, I would be grateful.
          >