I’m getting quite close to this now thanks to some great help from members of this forum. I’ve taken over a tricky (for me) job for a client producing an interactive map.
The map has a number of icons placed on the map using an xml script to title them, define their xy co-ordinates etc. and a right hand menu that lists all the locations, also created with the help of the same xml file, and which, when clicked on moves the map to the relevant icon. The problem I’m having is that I can’t get an active state to work on the icons when a button on the right hand menu is clicked. I’m really just trying to change the alpha status of the relevant icon.
The icon itself changes when clicked using ‘e.currentTarget’ but not when a menu item is clicked. I believe it has something to do with populating an Array but I can’t figure out how to do this - Can anyone help?
You can see my progress here, which probably explains the problem I’m having a little better - bit.ly/LrK8kF
The code I have to date that places the icons on the stage and the click function to change it’s alpha property is as follows:
// locating the landmarks on the map’s container
public function locateLandmarks():void {
for (var i:int = 0; i < landmark.length; i++) {
var landmarkIcon:MovieClip = new Landmark(landmark*.icon);
landmarkIcon.x = landmark*.x;
landmarkIcon.y = landmark*.y;
landmarkIcon.id = i;
landmarkIcon.alpha = .2;
landmarkIcon.buttonMode=true;
landmarkIcon.addEventListener(MouseEvent.CLICK, landmarkClick);
landmarkIcon.addEventListener(MouseEvent.ROLL_OVER, landmarkOver);
landmarkIcon.addEventListener(MouseEvent.ROLL_OUT, landmarkOut);
MovieClip(parent).pan.landmarks.addChild(landmarkIcon);
// Click Function
function landmarkClick(e:MouseEvent):void {
var id:int = e.target.parent.parent.parent.id;
gotoLandmark(id);
// navigate to target url
// if (landmark[id].target != undefined) MovieClip(root).testit.gotoAndPlay(landmark[id].target);
// Change Alpha on click
curr = e.currentTarget as MovieClip;
curr.alpha = 1;
curr.mouseEnabled = false;
if(prev)
{
prev.alpha = .2;
prev.mouseEnabled = true;
}
prev = curr;
}
}
}
and the script I have that creates the side menu is :
public function addButton(id:Number):void {
var targetCategory:String = landmark[filterArray[id]].category;
// attaching the category button if it isn’t aleady attached.
if (menu.container[targetCategory] == null) {
menu.container[targetCategory] = new GroupCategory(scrollWidth);
menu.container[targetCategory].button_category.categoryName.text = targetCategory;
}
var button:MovieClip = new LandmarkButton(scrollWidth);
button.landmarkName.text = landmark[filterArray[id]].name;
button.landmarkAddress.text = landmark[filterArray[id]].address;
if (landmark[filterArray[id]].thumbnail != undefined) {
button.thumbnail(landmark[filterArray[id]].thumbnail);
}
button.y = menu.container[targetCategory].container.height;
button.navigation = this;
button.id = id;
// landmark button events
button.addEventListener(MouseEvent.CLICK, buttonClick);
button.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
button.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
menu.container[targetCategory].container.addChild(button);
menu.container[targetCategory].count+=1;
}
private function buttonClick(e:MouseEvent):void {
var id:int = e.target.parent.id;
gotoLandmark(id);
}