So I’m just getting into AS3 and I’m actually liking it a lot. Makes things much more organized. However, I’m confused as how to reference methods in different places. I understand that I can reference a method of class that I pull into something, but how do I do it the other way around? Am I even supposed to? Let me explain more:
My Class:
[AS]
package com.selectBox{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import com.selectBox.DropDownItem;
public class DropDown extends Sprite{
public function DropDown(xmlObject:XML){
//find resort object in xml
var regionList:XMLList = xmlObject.region;
// add submenu items to holder and apply button functionality
for(var q:Number = 0; q<regionList.length(); q++){
var tmpText:String = regionList[q].attribute('title');
var tmpID:String = regionList[q].attribute('id');;
tmpText = tmpText.toUpperCase();
var subMenu:DropDownItem = new DropDownItem(tmpText);
subMenu.y = subMenu.height*q;
subMenu.ID = tmpID;
//subMenu.addEventListener(MouseEvent.CLICK, onSubmenuClick);
subMenu.mouseChildren = false;
subMenu.buttonMode = true;
subMenu.addEventListener(MouseEvent.ROLL_OVER, onSubmenuOver);
subMenu.addEventListener(MouseEvent.ROLL_OUT, onSubmenuOut);
subMenu.addEventListener(MouseEvent.CLICK, onSubmenuClick);
addChild(subMenu);
}
}
private function onSubmenuOver(evt:MouseEvent):void{
evt.currentTarget.onOver();
}
private function onSubmenuOut(evt:MouseEvent):void{
evt.currentTarget.onOut();
}
private function onSubmenuClick(evt:MouseEvent):void{
parent.updateDropDown(evt.currentTarget.ID, evt.currentTarget.btnName.text);
}
}
}
[/AS]
My Stage:
[AS]
import com.selectBox.DropDown;
import com.utilities.SimpleRectangle;
var xmlLoader:URLLoader = new URLLoader();
var regionData:XML = new XML();
var subMenu_holder:Sprite;
var subMenuY:Number;
var subMenuisOpen:Boolean = false;
//load up regional information
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(“regions.xml”));
//build regional dropdown menu
function LoadXML(e:Event):void {
regionData = new XML(e.target.data);
// create holder for sub menu items
subMenu_holder = new Sprite();
addChild(subMenu_holder);
// add menu items
var dropDown:DropDown = new DropDown(regionData);
subMenu_holder.addChild(dropDown);
// we don't know how many items there are so we have to wait until after filling it
// and then subtract the height of it (plus some padding) from the y of the box
subMenu_holder.x = content_com.x + content_com.combo_mc.x;
subMenu_holder.y = (content_com.y + content_com.combo_mc.y) - (subMenu_holder.height + 5);
//set starting/end y position of subMenu_holder
subMenuY = subMenu_holder.y;
//create mask for the menu just below box
var subMask:SimpleRectangle = new SimpleRectangle;
subMask.x = content_com.x + content_com.combo_mc.x;
subMask.y = content_com.y + content_com.combo_mc.y + content_com.combo_mc.height;
subMask.width = subMenu_holder.width;
subMask.height = subMenu_holder.height;
subMenu_holder.mask = subMask;
addChild(subMask);
}
function updateDropDown(ID:Number, _label:String):void{
trace(ID, _label);
}
[/AS]
My question lies in the onSubmenuClick function in my class. I want to update a function on the stage with the info contained in the item clicked on when the user click on that item. What is the best way to do this? or like I said, how do I do this the “right way”?