Hi,
I've been trying to create a carousel class which takes an array of phrases and then creates a textfield for each one positioning it vertically based on the order it was added. The next stage would be for it to make the phrases move down the _y axis until they reach the limit of the container. The phrases need to then swap onto a container behind or drop depths so they are behind the other phrases and then make their way back up. The general idea being like an upright carousel.
I first tried to create it in one class (PhraseCarousel), but then i thought maybe it would be better to separate it into two classes so there's one for the phrase objects aswell (PhraseObject), i did this because i was thinking that i should give the moving behaviour to the phrase objects instead of dealing with that in the carousel.
Anyway where I'm struggling at the moment is how to best add the PhraseObject instances, do I attach them to the main timeline or do i add them to an array on the main timeline and then pass them to the carousel class?
I'm a bit new to OOP so my code is not really making all that much sense at the moment:
-
class PhraseObject extends MovieClip {
-
-
private var phrase:String;
-
private var textObject:TextField;
-
private var startPositionY:Number;
-
private static var count:Number = 0;
-
private static var mTimeLine;
-
private var depth:Number;
-
private var container:MovieClip;
-
-
function PhraseObject(pTimeLine:MovieClip,phrase:String,startPositionY:Number) {
-
-
// Initialise variables
-
trace("PhraseObject, initialising...");
-
this.phrase = phrase;
-
this.startPositionY = startPositionY;
-
-
// Set the timeline to attach the phrase object to
-
mTimeLine = pTimeLine;
-
-
// Set the depth for the object
-
depth = mTimeLine.getNextHighestDepth();
-
-
// Create a movieclip for the object
-
container = mTimeLine.createEmptyMovieClip("container"+depth,depth);
-
-
// Add the text to the phrase object
-
createPhraseObject();
-
-
// Update
-
updatePhraseNumber();
-
}
-
function createPhraseObject() {
-
-
// Create textfield
-
textObject = container.createTextField("phrase_"+count+"_txt",count, 100, 100, 300, 100);
-
textObject.color = 0xFF0000;
-
textObject.text = this.phrase;
-
textObject._x = 0;
-
textObject._y = startPositionY;
-
-
// Return a reference
-
return container;
-
}
-
public function setY(newY:Number) {
-
-
this._y = newY;
-
-
}
-
private static function updatePhraseNumber() {
-
-
trace("Updating count: "+count);
-
count++;
-
return count;
-
-
}
-
-
}
-
Hope someone can point me in the right direction, thanks.
chromis