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...
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?
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.
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.");}
}
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.
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.
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?
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. -
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