Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-26-2007, 01:54 AM   #1
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 92
Default inheritance issue in AS3

Hi every one, yes i am finally on AS3 and for good now, so this is my question.
I have created a SelectionSystem class that creates instences of a UIButton class and place them one after an other horizontaly.
My button MC has a hitZone and a titleMc Movieclips.
Every thing is working up to that point, the issues arise with "inheritance" form when i tried to create the VerticalMenu classes that is supposed to extends UIButton
and overright the function setPosition() to place the button in a vertical manner. i am getting this: "1120: Access of undefined property hitZone.", "1120: Access of undefined property titleMC."
now that in the linkage box of my Button i have put VerticalMenu it doesn't find hitZone or titleMc.
I have flipped every witch way i just cant figure it out, some help would be grealy apreciated as i am just stating on my AS3 journey ...


my Classes:


Code:
package 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	

	public class UIButton extends MovieClip
	{

		public var id:uint;
		private var visited:Boolean;
		private var selected:Boolean;
		//public var hitZone:MovieClip;
		//public var titleMc:MovieClip;

		public function UIButton()
		{
			//initMouseEvents();
		}
		public function Init(_systemData:Object, _id:Number)
		{
			id = _id;
			setTitle(_systemData.Title);
			setPosition();
			//trace(2);
		}
		//MouseInit
		
		private function initMouseEvents()
		{
			//var hitZone:MovieClip;
			hitZone.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
			hitZone.addEventListener(MouseEvent.MOUSE_UP, handleUp);
			hitZone.addEventListener(MouseEvent.MOUSE_OVER, handleOver);
			hitZone.addEventListener(MouseEvent.MOUSE_OUT, handleOut);
			//hitZone.addEventListener(MouseEvent.CLICK, handleClick);
			hitZone.buttonMode = true;

		}
		private function removeMouseEvents()
		{
			//var hitZone:MovieClip;
			hitZone.removeEventListener(MouseEvent.MOUSE_DOWN, handleDown);
			hitZone.removeEventListener(MouseEvent.MOUSE_UP, handleUp);
			hitZone.removeEventListener(MouseEvent.MOUSE_OVER, handleOver);
			hitZone.removeEventListener(MouseEvent.MOUSE_OUT, handleOut);
			//hitZone.removeEventListener(MouseEvent.CLICK, handleClick);
			hitZone.buttonMode = false;
		}
		//set
		private function setTitle(_title:String)
		{
			//var titleMc:MovieClip;
			titleMc.titleTxt.text = _title;
		}
		private function setPosition()
		{
			this.x = (this.width + 2)*id;
		}
		//handle
		private function handleOver(event:MouseEvent):void
		{
			MouseRollOver();
		}
		private function handleOut(event:MouseEvent):void
		{
			MouseRollOut();
		}
		private function handleDown(event:MouseEvent)
		{
			MouseDown();
		}
		private function handleUp(event:MouseEvent)
		{
			MouseUp();
		}
		private function handleClick(event:MouseEvent)
		{
			//
		}
		//select
		public function setSelected()
		{
			visited = selected = true;
			this.gotoAndPlay("over");
			removeMouseEvents();
		}
		public function setUnselected()
		{
			selected = false;
			initMouseEvents();
			MouseRollOut();
		}
		//goto
		private function MouseRollOver()
		{
			this.gotoAndPlay("over");
		}
		private function MouseDown()
		{
			this.gotoAndStop("down");
		}
		private function MouseUp()
		{
			this.gotoAndStop("up");
		}
		private function MouseRollOut()
		{
			if (visited)
			{
				this.gotoAndPlay("visited");
			}
			else
			{
				this.gotoAndPlay("out");
			}
		}
		
	}
	
}


//-------------------------------

package 
{
	import UIButton;
	
	
	class VerticalMenu extends UIButton
	{
		//public var hitZone:MovieClip;
		
		public function VerticalMenu(){}

					
		
		
		private function setPosition()
		{
			//this.x = (this.height + 10)*id;
		}
		
	}
	
}

//---------------------------------

package 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class SelectionSystem extends MovieClip
	{
		private var systemData:Array;
		private var currentSelection:Number;
		private var listItems:Array;

		public function SelectionSystem()
		{

		}
		public function Init(_systemData:Array)
		{
			listItems = new Array();
			systemData = _systemData;
			Render();
		}
		private function Render()
		{
			for (var i:uint=0; i<5; i++)
			{
				var item:MovieClip = new VerticalMenu;
				item.Inito(systemData[i], i);
				item.name = "btn" + i;

				item.addEventListener(MouseEvent.CLICK, handleClick);
				addChild(item);
				listItems.push(item);
			}
		}
		private function handleClick(event:MouseEvent)
		{
			var id:uint = event.currentTarget.id;
			setSelection(id);
			doAction();
		}
		public function setSelection(_id:uint)
		{
			if (currentSelection != _id)
			{
				if (!isNaN(currentSelection))
				{
					listItems[currentSelection].setUnselected();
				}
				currentSelection = _id;
				listItems[currentSelection].setSelected();
			}
		}
		
		private function doAction(){
			//trace(systemData[currentSelection].Url);
		}

	}
}


//---------------------------


var menuData:Array = new Array();


menuData = [
			{Title:"Btn 1", Url:"0"},
			{Title:"Btn 2", Url:"1"},
			{Title:"Btn 3", Url:"2"},
			{Title:"Btn 4", Url:"3"},
			{Title:"Btn 5", Url:"4"}
			];

btnMenu.Init(menuData);
//btnMenu.setSelection(2);


//----------------
BrettAF3D is offline   Reply With Quote
Old 07-26-2007, 07:52 AM   #2
jorrit5477
Registered User
 
Join Date: Jul 2007
Posts: 22
Default

Is it correct both hitZone and titleMC are commented out?
jorrit5477 is offline   Reply With Quote
Old 07-27-2007, 12:25 AM   #3
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 92
Default Still Trying

yes, well i was just trying different things, have you tried the code ?, Basicly the "Model/Concept" is all based on the book "flash application design solution" but the book was written in AS2 so i am trying to recreate the classes in AS3....but right now i can't find the solution. Every thing is working fine until you start using inheritance. After using inheritance if you have a MC1 in the MC that you have exended it doesn't recognize MC1.... and i can't find the way to declare MC1 in either classes ...
BrettAF3D is offline   Reply With Quote
Old 07-27-2007, 08:35 AM   #4
matzo
Registered User
 
Join Date: Jul 2007
Posts: 1
Default

To override a method in Actionscript 3.0 you must use the 'override' keyword with exactly the same method signature.
(so a private method can't turn public, or a method returning void, cannot be overridden to return boolean)

ActionScript Code:
override private function setPosition()
in your vertical Menu class

Last edited by matzo; 07-27-2007 at 08:37 AM.
matzo 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
Embed swf assets in Flash 9 AS3 - not flex not flashdevelop Birdsong ActionScript 3.0 11 09-02-2010 12:48 PM
AS3 loads AS2 swf. AS2 swf not displayed darbar ActionScript 3.0 0 07-20-2007 09:12 PM
Migration to AS3 jsimpson ActionScript 2.0 0 06-08-2007 04:38 PM
Inheritance issue... mkulture ActionScript 2.0 1 03-17-2005 08:59 AM
streaming issue in Flash MX player (versions prior to 6,0,29,0) suhaskots ActionScript 1.0 (and below) 0 02-11-2003 04:23 AM


All times are GMT. The time now is 09:45 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.