A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: extend MovieClip class

  1. #1
    Junior Member
    Join Date
    Feb 2005
    Posts
    5

    extend MovieClip class

    I would like to write some clips, but it seems do not work.

    my test.as file:
    class test extends MovieClip {
      function test() {
        this.lineStyle(1, 0xff0000, 100);
        this.moveTo(50,50);
        this.lineTo(111,111);
      }
    }


    code in first frame script:
    var aline;
    aline = new test();
    stop();


    Why the clip does not draw anything!?

    But if i modify the class definition as follows:
    class test extends MovieClip {
      var mc;
      function test() {
        this.mc = _root.createEmptyMovieClip( "mc1", 10);
        this.mc.lineStyle(1, 0xff0000, 100);
        this.mc.moveTo(50,50);
        this.mc.lineTo(111,111);
      }
    }


    evrything is ok.

    So, must be create a property and assign a new mc to it,
    or it possible to use simply the this. object for drawing ?

    Thanks if someone could help.

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    create a new movie clip and from the linkage options select export for actionscript. Give the clip a linkage identifier and fill in the name of your class in the AS2 class name field.

    now you can create an instance of your class using attachMovie,

    this.attachMovie("linkage_identifer", "newName", depth);

  3. #3
    Junior Member
    Join Date
    Feb 2005
    Posts
    5
    yes, you all right

    with this method you should make a symbol in the library for every clips

    i would prefer to maintain it only in actionscript code, if possible

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    you dont have to make movie clips for every class. You can use Object.registerClass to associate classes with library items dynamically as needed. Also, if you are simply using empty clips, an empty movie clip is automatically created for your class in your library with the linkage id __Packages.[full class name]. So you could just use that without defining any symbols yourself.

  5. #5
    Junior Member
    Join Date
    Feb 2005
    Posts
    5
    Dear Senocular !

    It is interesting, seems to be a good idea.
    A read the Object.registerClass docs before, but the workaround is not fully clear.

    Should you write a short example, or reference an example source.

    thanks: newbye

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    Using Object.registerClass isn't a workaround. It's the purpose of the function. What about it don't you understand?

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