Skip to main content
Handycam
Known Participant
March 26, 2008
Question

objects appear & disappear with slider

  • March 26, 2008
  • 3 replies
  • 396 views
I have a project with a map that has points that appear or disappear based on the position of a slider.

For example, if the slider is within 10 units of 1000 (990-1010), show this point, otherwise hide that point.

What's the best way, in your opinions, to manage this?

So far, I have a change event listener on the slider that fires this function:
function sliderChange(e:SliderEvent):void {
if (e.target.value == 1500) {
makeBox();
}
}

MakeBox is a function that draws the rect that acts as my "point" (for now). This works but doesn't seem very scalable. So I'm seeking conceptual advice on the best way to make this handle a couple dozen points.

Thanks.
This topic has been closed for replies.

3 replies

Inspiring
March 27, 2008
You're welcome.

You could also make them a little easier to instantiate
by passing info to the constructor. Something like:

// new ctor
public function MapPoint(slider:Slider=null,
pointValue:uint=0, pointTolerance:uint=10)
{
super();
this.slider=slider;
this.pointValue = pointValue;
this.pointTolerance = pointTolerance;
var g:Graphics = this.graphics;
g.beginFill(0xff0000, 1);
g.drawRect(0,0,3,3);
g.endFill();
}



// and then

import fl.events.*;
var point1:MapPoint = new MapPoint(mySlider,100);
var point2:MapPoint = new MapPoint(mySlider,150);
point1.x=point1.y=50;
point2.x=point2.y=150;
addChild(point1);
addChild(point2);



Handycam
HandycamAuthor
Known Participant
March 27, 2008
Yes, thanks. I couldn't figure out how to make my class listen to the slider in the main app. I'm still a bit sketchy on getters and setters, I guess.
March 27, 2008
Just speculating, but you might want to make your points DisplayObjects, and have the points listen for slider events. Something like this: