I'm not sure I even labelled this correctly, but here's my problem.
I have five instances of object "Category", of which each in turn create instances of object "Tab".
the 5 instances of category, when created, are pushed to an array, which is sitting inside a class named "ButtonGroup" - ButtonGroup exists so I can addEventListeners to the Tabs from one central place which allows me to modify all the tabs in one place when a button gets pressed instead of setting up Broadcasters for every tab instance.
The event listener has been put upon Category Object>Tab Object> tabElement:MovieClip, ala
Code:
theTab.tab.tabElement.addEventListener(MouseEvent.MOUSE_UP, tabClicked);
Withing tabClicked function, I have:
Code:
selectedTab = event.currentTarget;
Hence, selectedTab is the tab I just clicked on. However, herein lies my problem. If I try to discover that tabs "Tab" instance, I can't, because the event.currentTarget.parent would be the stage...not the Tab object instance it is associated with!
How can I find what Tab instance it is associated with??
Here my class files - if they help.
HomeFlash.as
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class HomeFlash extends MovieClip {
//public var category:Array = new Array();
public var category:Array;
public var buttonGroup:ButtonGroup;
//Constructor
public function HomeFlash() {
trace("im in your constructor, tracing all your code");
buttonGroup = new ButtonGroup();
//category = buttonGroup.getCategories();
//add the all the buttons into the array.
addContents();
//Because "Hosting" is just one word, I need to move tab one into middle
//Ideally, I should be checking all tabs for text length and positioning them appropriately
tab1.button.tabText.y = 10;
}
//Adds each orb into the array
public function addContent(cItem:Category):void {
//add to teh animation handler
//category.push(cItem);
buttonGroup.addCategory(cItem);
}
//Declare all the information to go into the array
private function addContents():void {
addContent(new Category(tab1,"HOSTING", new hosting()));
addContent(new Category(tab2,"WEB" + "\n" + "DESIGN", new web_design()));
addContent(new Category(tab3,"WEB" + "\n" + "DEVELOPMENT", new web_dev()));
addContent(new Category(tab4,"VOIP" + "\n" + "SERVICES", new voip_services()));
addContent(new Category(tab5,"NETWORK" + "\n" + "SERVICES", new network_services()));
}
}
}
Category.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
/* Orb Class*/
public class Category {
private var _tabElement:theTab;
private var _tabLabel:String;
private var _tabIcon:MovieClip;
private var _tab:Tab;
//Costructor
public function Category(tabElement:theTab, tabLabel:String, tabIcon:MovieClip) {
this._tabElement = tabElement;
this._tabLabel = tabLabel;
this._tabIcon = tabIcon;
//Creates a new instance of tab
_tab = new Tab(_tabElement, _tabLabel, _tabIcon);
}
//Getter functions
//Allow these functions to be called outside of this class but not be written over.
public function get tabElement():MovieClip { return _tabElement; }
public function get tabLabel():String { return _tabLabel; }
public function get tabIcon():MovieClip { return _tabIcon; }
public function get tab():Tab { return _tab; }
}
}
Tab.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
/* Tab Class*/
public class Tab {
private var _tabElement:MovieClip;
private var tabLabel:String;
private var tabIcon:MovieClip;
private var tabActive:Boolean = false;
public var tabClickTime:Number = 50;
public var tabClickTimer:Timer;
public var clip:MovieClip;
public var category:Category;
//Costructor
public function Tab(tabElement:MovieClip, tabLabel:String, tabIcon:MovieClip) {
//Just store some variables
this._tabElement = tabElement;
this.tabLabel = tabLabel;
this.tabIcon = tabIcon;
this.clip = this._tabElement;
//Call function to add content onto each tab
populateTab(this.tabElement, this.tabLabel, this.tabIcon);
}
public function populateTab(_tabElement:MovieClip, tabLabel:String, tabIcon:MovieClip){
//Set the text on each tab
_tabElement.button.tabText.text = tabLabel;
//Add the icon onto each tab
_tabElement.button.addChild(tabIcon);
//Setting position and transparency of the icon on each tab
tabIcon.alpha = 0.4;
tabIcon.x = 8;
tabIcon.y = (39 - tabIcon.height)/2;
}
public function turnOff(){
tabElement.onTab.visible = false;
}
public function turnOn(){
tabElement.onTab.visible = true;
}
public function get tabElement():MovieClip { return _tabElement; }
}
}
And finally, ButtonGroup.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
public class ButtonGroup {
public var tabs:Array = new Array();
public var selectedTab;
public function ButtonGroup() {
}
public function addCategory(theTab:Category):void {
tabs.push(theTab.tab);
//trace(tab);
trace(theTab.tab);
theTab.tab.tabElement.addEventListener(MouseEvent.MOUSE_UP, tabClicked);
}
public function tabClicked(ev:MouseEvent):void {
//loop through tabs:Array and turn all tabs "off"
for each (var tab:Tab in tabs) {
tab.turnOff(); //turn off function?? tab.visible = false;?
}
//set the newly selected tab
selectedTab = ev.currentTarget; //tab that triggered event
//turn it on, 'selected' references the tab that was just pressed
//selectedTab.turnOn(); //dont know what your function is? tab.visible = true;?
}
public function get getCategories():Array { return tabs; }
}
}