Firstly ::
I know there are plenty of tutorials that will show what I’m wanting to know.
However I’m finding it difficult to grasp concepts as the tutorials are not related to what I am doing and then is for me to make a similar outcome relevant to my project!
Ok here we go::
Please trust me when I say I have done A LOT of reading before starting to use AS3 and while liking OOP to cars/bicycles/toasters/buildings/etc I still dont have a clue on how to effectively use classes I make.
So at this point would I be right in saying a class is a blueprint that I can make objects out of. So I could make a generic class shape, and then make a subclass that extends shape into something more specific like a square, the square will inherit all the properties and functions of square… right? So then Time and effort is saved because the functions of shape are already in square now, so recoding is not a problem…
And if I am right with that crude example, could you guys help me with an example more relevant to what I’m doing. I don’t feel that thinking about shapes is helping me understand fully.
Basically I have a bar that slides onto the screen when the mouse has rolled over it and slides of nearly all of the way when the mouse rolls off. I have two of bars one of the left side of the screen and one for the bottom.
Now both bars perform the same functions but in terms of the information they carry their size and the positions they move to the are different.
If I was to make a class called Infobars that contained all of the properties and functions to make an Infobar, could I then use subclasses to extend the Infobars into different sidebars, calling on the functions that were defined in Infobars, but editing the size and positions of the bars?
Now if I hadn’t typed enough…(sorry about this =S ) Could I ask you lovely people to help me make example scripts that demonstrate what I have been talking about providing of course what I have been typing is right.
Here is how I think the Infobars could be created::
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.Event;
public class Infobar extends Sprite {
private var _slideTo:Number;
public function Infobar() {
var makeRect:Sprite=new Sprite ;
var dC:Graphics=makeRect.graphics;
dC.lineStyle(3,0x000000,1);
dC.beginFill(0xff0000,1);
dC.drawRect(0,0,200,500);
dC.endFill();
addChild(makeRect);
this.addEventListener(MouseEvent.ROLL_OVER,slideIn,false,0,true);
this.addEventListener(MouseEvent.ROLL_OUT,slideOut,false,0,true);
}
private function slideIn(evt:Event) {
this.addEventListener(Event.ENTER_FRAME, smoothSlide, false, 0,true);
_slideTo = 350;
}
private function slideOut(evt:Event) {
this.addEventListener(Event.ENTER_FRAME, smoothSlide, false, 0,true);
_slideTo = 500;
}
private function smoothSlide(evt:Event) {
var _speed = 5;
if (this.x > _slideTo || this.x < _slideTo ) {
var thisX:Number = this.x;
this.x += (_slideTo-thisX)/_speed;
}
}
}
}// note that when this movie starts you have to move your mouse over the rectangle before it will go to its rightful place. *shrugs* I don't know why, this didn't happen before
So that is class I want to base my future sidebars on. How would the subclasses be
created and made different shapes to this example. ans would the functions work automatically? BTW in reality the sidebar shapes are ones that I had made and exported, i changed it for this script to make things easier
I have already got my side bars working I’m just using them as a platform to understanding classes a bit more…
I hope people understand what I’m asking and can help. And if you have made it down here Thanks for reading!