Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-14-2008, 02:42 AM   #1
pinkshiro
Senior Member
 
Join Date: Mar 2006
Posts: 116
Default Associating event.currentTarget back to it's class instance?

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; }
		
	}
}
pinkshiro is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning the instance name of a class from within the instance jeremydore ActionScript 2.0 5 06-06-2006 04:14 PM
Please comment on slideshow class rune_kg ActionScript 2.0 15 04-01-2006 02:50 AM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
Call method, not new class instance Sarah012 ActionScript 2.0 2 05-15-2004 09:41 AM
inheritance - Mortimer Jazz ActionScript 1.0 (and below) 10 07-24-2003 09:51 PM


All times are GMT. The time now is 05:10 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.