I have just created this code to dynamically create a list of sliders.
//import slider classes
import fl.controls.Slider;
import fl.events.SliderEvent;
import fl.controls.Button;
import flash.events.*;
import flash.net.*;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
var imageText:TextField;
var slider:Slider;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("xml/myXMLdata.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
// converts data into xml data which flash can understand
xml = XML(event.target.data);
// places xml data into a list/array
xmlList = xml.children();
for (var i:int=0;i<xmlList.length(); i++)
{
slider = new Slider();
slider.x = 25
slider.y = i * 50 + 25;
// control if slider updates instantly or after mouse is released
slider.liveDragging = false;
//set size of slider
slider.setSize(200,0);
//set maximum value
slider.maximum = 100;
//set mininum value
slider.minimum = 0;
//Gets or sets the initial value of the Slider.
slider.value = xmlList*.attribute("initial");
//set tick position interval, you do not have to set this
slider.tickInterval = xmlList*.attribute("tick");
// sets the increment by which the value is increased or decreased.
slider.snapInterval = xmlList*.attribute("snap");
// this is a listener that broadcasts evertime an event changes
slider.addEventListener(SliderEvent.CHANGE, announceChange);
// add slider to stage
container.addChild(slider);
slider.name="slider"+i;
trace(slider.name);
}
}
function announceChange(e:SliderEvent):void {
//this line gives the current position of target slider
trace(e.target.name + " value is now: " + e.target.value);
//this code throw up an error. Obviously Im doing something wrong
for (var i:int=0;i<xmlList.length(); i++)
{
trace(container["slider"+i].value);
}
}
What I need is a function which collects ALL the slider values. Not just the one being moved. However I cant work out how to access the instance names i created trace(slider.name). Maybe I need to do is create an array then update the relevant slider value when it is changed. I have tried to do this, but I cant work it out.
Im a bit lost here, could I get a little guidance?
Thanks,
J