简体   繁体   中英

Actionscript 3 modify Label Component text

I'm trying to modify the text of a Label component that I already placed on the stage in as3. I'm having trouble getting the text to change though, it just stays the same based on the inital text I typed in. I'd like to eventually have the label contents change dynamically. When I compile the swf, the two labels have the original value I gave them when I put them on the stage, not the startDate and endDate values. My code looks like:

package
{
    import flash.display.*;
    import fl.controls.Slider; 
    import fl.events.SliderEvent; 
    import fl.controls.Label; 

    public class slider extends MovieClip{

        public var startDate:int;
        public var endDate:int;

        public function slider(){
            dateSlider.addEventListener(SliderEvent.CHANGE, changeHandler); 
            startDate = 1981;
            endDate   = 1995;
            startLabel.text = startDate.toString();
            endLabel.text   = endDate.toString();
        }

        private function changeHandler(event:SliderEvent):void { 
            yearLabel.text = (event.value/10) + startDate + " year";     
        }
     }

}

Thanks

I assume your are trying to change button label. Are you?

If yes, then do

startLabel.label = startDate.toString(); instead of startLabel.text = startDate.toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM