I’m in the process of learning OOP and have run into a small problem. I’m trying to create a basic menu system where you can rollover and rollout of all links. When you select a link, it stays highlighted until you click another link.
I’ve given the 5 links instance names like (link0, link1, link2, link3, link4) and given them each an ID of (0,1,2,3,4) - respectively. I used to be able to do something like this:
this.onRollOver = function(){
if(this.ID != _root.selectedLink){
this.gotoAndPlay('in');
}
}
this.onRollOut = function(){
if(this.ID != _root.selectedLink){
this.gotoAndPlay('out');
}
}
this.onRelease = function(){
if(this.ID != _root.selectedLink){
_root['link'+_root.selectedLink].gotoAndPlay('out');
_root.selectedLink = this.ID;
}
}
My question for OOP though is this line: _root[‘link’+_root.selectedLink].gotoAndPlay(‘out’);
How can I mimik this? Should I not even put it in the OOP - should I be putting the rollovers, rollouts, and releases on the main stage that calls a function in the OOP? I’m a bit lost on this - any help would be much appreciated!
Here is my current code:
mainStage:
for (var i in a) {
var mc = nav_com.attachMovie("mainLink", "link"+i, i);
mc.Node = a*;
mc.ID = i;
mc._y = 0;
mc._x = mc._width*i;
}
OOP code:
class com.MainMenuItem extends MovieClip {
private var linkLabel:MovieClip;
private var node:XMLNode;
private var myID:Number;
public function MainMenuItem() {
linkLabel = eval(this._target+"/linkText_mc");
}
public function set Node(n:XMLNode) {
node = n;
linkLabel.link_txt.text = n.attributes.label;
}
public function get Node():XMLNode{
return node;
}
public function set ID(id:Number){
myID = id;
}
public function get ID():Number {
return myID;
}
public function onRollOver() {
if(this.ID != _root.selectedLink){
gotoAndPlay('in');
}
}
public function onRollOut() {
if(this.ID != _root.selectedLink){
gotoAndPlay('out');
}
}
public function onRelease() {
if(this.ID != _root.selectedLink){
trace(_root['link'+_root.selectedLink]);
_root['link'+_root.selectedLink].gotoAndPlay('out');
_root.selectedLink = this.ID;
}
}
}