A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Extending Classes in Actionscript 3.0

  1. #1

    Question Extending Classes in Actionscript 3.0

    I created a class called Car. My "driver" movie calls "Car" in the as its main associated actionscript class.

    I want to extend Car.

    I did
    public class Honda extends Car{
    ......

    in a separate AS3 class in the same folder.
    But how can I instantiate a Honda ? (make a new Honda) ? Wherever I try to do it, I get an error.

    How does Flash "know" that the Honda is part of the same package?
    Anyone?
    -Nmuta

  2. #2
    Anyone?....
    anyone?...

    Beuller?
    -Nmuta

  3. #3
    of CommentCreative.com
    Join Date
    Jan 2011
    Location
    Lansing, Michigan
    Posts
    2
    It knows where it is via the package declaration in the class (which has to match the folders the class is in) and then in the script where you use the class you need to import that class using the fully qualified name including the package.

    For example you have the class in folder2 which is inside folder1. Your class needs to say:

    package folder1.folder2
    {
    // don't forget to import the class you are extending into the class
    import folder1.folder2.Car;

    public class Honda extends Car
    {

    }
    }

    And then in the script where you use it you'd have to go:

    import folder1.folder2.Honda;
    var myHonda: Honda = new Honda();

  4. #4
    of CommentCreative.com
    Join Date
    Jan 2011
    Location
    Lansing, Michigan
    Posts
    2
    well the code didn't work well, guess I should put it in tags:

    Actionscript Code:
    package folder1.folder2
    {
        // don't forget to import the class you are extending into the class
        import folder1.folder2.Car;

        public class Honda extends Car
        {
           
        }
    }

    and in the place it's used:

    Actionscript Code:
    import folder1.folder2.Honda;
    var myHonda: Honda = new Honda();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center