A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: extends MovieClip

  1. #1
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280

    extends MovieClip

    Anyone know of a great tut for creating an AS2.0 script for extending a MovieClip? Too many problems to post to the forums as of now... would like to try and nail this one down with a little bit of reading first.

    I do have one problem someone might be able to help me with...

    Code:
    class SandBox extends MovieClip {
    ...
    function importImage (newImage:MovieClip) {
        trace( newImage );
        newImage.duplicateMovieClip( "mcSwap", 100 );
        trace( this[ "mcSwap" ] );
        this[ "mcSwap" ]._alpha = 0;
        this.onEnterFrame = newImageHandler;
    }
    ...
    }
    The trace output shows _level0.mcImageImport (for the trace( newImage ) ) so I know the mc is being passed as a parameter... but the trace( newImage) always comes up undefined... why is the duplicateMovieClip failing?

  2. #2
    Re Member websam's Avatar
    Join Date
    Jul 2000
    Location
    Australia (VIC)
    Posts
    660
    code:

    class SandBox extends MovieClip {
    public function SandBox(){}
    function importImage (newImage:MovieClip,lvl:Number):String {
    trace( newImage._name );
    newImage.duplicateMovieClip( "mcSwap"+lvl, lvl);
    trace("mcSwap"+lvl );
    this[ "mcSwap" +lvl]._alpha = 50; // change to 50 for verification
    return ("mcSwap" +lvl);
    // this[ "mcSwap" +lvl].onEnterFrame = newImageHandler;
    // remarked as I don't hae your newImageHandler
    }
    }



    By assign level num dynaically will make this class more dynamic to handle multiple new MCs at once.
    Attached Files Attached Files

  3. #3
    Re Member websam's Avatar
    Join Date
    Jul 2000
    Location
    Australia (VIC)
    Posts
    660
    Delux Version...

    in *.as
    code:

    class SandBoxDlx extends MovieClip {
    public function SandBox(){}
    function importImage (newImage:MovieClip,lvl:Number):MovieClip {
    trace( newImage._name );
    return newImage.duplicateMovieClip( "mcSwap"+lvl, lvl);
    }
    }




    in *.fla
    code:

    var nmc:SandBoxDlx=new SandBoxDlx();
    for (i=1;i<=3;i++) {
    obj= nmc.importImage(_root.mc,i);
    with(obj){
    _x = _root["tg"+i]._x;
    _y = _root["tg"+i]._y;
    }
    obj.onPress=function(){this.startDrag(0);trace(thi s._name + " is being dragged.");}
    obj.onRelease=function(){stopDrag();trace(this._na me + " has been dropped.");}
    }

    Attached Files Attached Files

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You find one in the flash help files. There are some tutorial examples. Great place to learn OOP.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Originally posted by websam
    class SandBoxDlx extends MovieClip {
    ...
    function importImage (newImage:MovieClip,lvl:Number):MovieClip {
    trace( newImage._name );
    return newImage.duplicateMovieClip( "mcSwap"+lvl, lvl);
    }
    }
    Well, I just re-read my original post, and accidentally mis-wrote my issue. The problem would be that the newImage parameter traces out correctly with the mc passed in from _level0, however, after I call duplicateMovieClip( "mcSwap", 100 ) on it... mcSwap, this[ "mcSwap" ], or any other derivative identifying the new mc, traces out to 'undefined'. Once I can get the duplicateMovieClip to work, the level will go down to -1, the 100 is only for testing purposes. Although I do agree with you regarding passing in the lvl (or using a rolling counter or whatever), it's not needed as the onEnterFrame function (newImageHandler()) will swap the new image in to the foreground, and set a flag which prevents new images from coming in. This part was left out as the duplicateMovieClip was the problem, and not the layering and such.

    The point behind the SandBox class is to be a container for a lab culture simulation, in which anywhere from 4 - 16 "petri dishes" will grow cultures under different conditions. The swapImage function will be used to change the background so that different colored cultures can be seen... all dishes will change at the same time.

  6. #6
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Originally posted by cancerinform
    You find one in the flash help files. There are some tutorial examples. Great place to learn OOP.
    Although the help files were OK, they don't deal with things like passing in parameters, dealing with super-classes, and such, only things like adding new functions and parameters. Basically, I'm creating a class all it's own, but I need the functionality of the MovieClip so that it will not only display, but can handle drawing functions and layering and loading movieclips.

    I don't have a problem with OOP, just the syntax of AS2.0 My background is in C/C++, Perl and PHP.

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Try video-animation.com
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Thanks for the site... not the prettiest thing in the world, but it's helped out a lot.

    And I believe I've found the problem with my duplicateMovieClip() dilemma. I'm sure I've seen this somewhere in the forums before, but must have slipped my mind...
    If you have loaded a movie clip using MovieClip.loadMovie() or the MovieClipLoader class, the contents of the SWF file are not duplicated. This means that you cannot save bandwidth by loading a JPEG or SWF file and then duplicating the movie clip.
    If I read this correctly, any background which I load dynamically, can not be duplicated anywhere inside of my SWF, correct? I must load the file again in to each MovieClip I want it to appear in?

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I tested once to load a pic into a movieclip and then I made sure the pic is loaded using getBytesLoaded() and interestingly the duplicated mc was undefined.
    - The right of the People to create Flash movies shall not be infringed. -

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Since you were looking for a tutorial on extending movieclips. I did some research on it and wrote a tutorial. I don't know it's great but I think I found some interesting and useful stuff. There are 2 parts. You might be interested in the second part

    http://www.flashscript.biz/MX2004/OO...l/lesson4.html
    - The right of the People to create Flash movies shall not be infringed. -

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