hello.
was looking into classes,
I wonder if they are needed,
Like i want to make a circle with a prototype added.
This doesnt work, and i wonder how i would make it work?(Might be lots of syntax here)
[AS]
class Circle{
this.isCrazy()
}
MovieClip.prototype.isCrazy = function (){
this.onEnterFrame = function (){
this._x = Math.Random()*20
}
}
[/AS]
Is classes needed for this? What good comes with classes?
I don’t really understand what you want to know/understand, your code won’t work because the class ‘circle’ is not a MovieClip, which will therefore not be affected by prototypes assigned to the MovieClip class. Look at the following.
/*********
** This should be inside a seperate AS file concidering its a class
*********/
class circle {
public var x:Number = 0;
function circle(x:Number){
trace("This is a circle class!");
this.x = (x != "undefined")? x : this.x;
}
}
/********
** This should be in the actual movie
********/
var c:circle = new circle(50); // Sets the class, and gives it the initial X value of 50
// This is your prototype
c.prototype.isCrazy = function(){
trace("This is a prototype function!");
this.onEnterFrame = function(){
this.x = Math.random()*20;
}
}
// Calling the function
c.isCrazy();
Hope that cleared up something, like I said, not sure what you were asking for.
Custom classes aren’t necassary, I’m not that into classes myself, however, classes are great. Especially for big projects, or code that you often rewrite. For smaller projects, or very specific things, classes can be a bit off track though.
Would really depend on your code If you feel that you keep repeating a lot of code for different things, that might be an idea, if you don’t really repeat that much, I wouldn’t worry about it, especially if your on about 500 rows already.