Skip to main content
Known Participant
May 19, 2011
Question

Assigning differnt values to slider bar

  • May 19, 2011
  • 1 reply
  • 590 views

Hi,

Im really new to actionscript so hopefuly im making sense, on the project im doing now i have a slider bar taken from the compnents in flash. What i want is to duplicate a movie clip i have on the stage randomly with in a nother movie clip called  square_mc. I have the movie clip spawning accoring to the slider value.

But what i want to happen is to sapwn the movie to a custom number assignd to certian incraments of the slider, instead of it spawn 1-11, which are my slider values. And each interval i go up the slider i want it to reset, so for e.g. the first incrament of the slider value is 2 and the second is 5, when i slide to the second one i only want 5 movie clips not 7.

This is the code i currently have.

            timeline_slider.addEventListener(SliderEvent.CHANGE, dotspawn);

        }
        function dotspawn(e:SliderEvent)
        {
        for( var i = -1; i < timeline_slider.value; i++ )
        {              
        var rd = new red_dot();              
        addChild( rd );              
        rd.x = square_mc.x + Math.random()* square_mc.width;              
        rd.y = square_mc.y + Math.random()* square_mc.height;       
        } 
        update(0);// do initial update;
        update(e.value);
        }

Thanks,

hen

This topic has been closed for replies.

1 reply

Kenneth Kawamoto
Community Expert
Community Expert
May 19, 2011

To customise the slider values you can set minumum and maximum (the default is 0 and 10 respectively), and also snapInterval.

Do you mean you want to clear the stage when the slider has ben changed? Before adding objects you can either remove all the objects you previously added using removeChild()/removeChildAt(), or add/remove only the difference - e.g. say if it was 5 and now 7, add 2 objects.

henhen01Author
Known Participant
May 20, 2011

Ok well ive seem to of got it working with the slider by using an array

Yeah, so for examle, if i slide the slider 2 incraments, it should have only (0001/100) Not (5516 / 100) + (0001 / 100)


var rdCounts:Array = [5516 / 100,0001 / 100,0053 / 100,0015 / 100,0011 / 100,0060 / 100,0148 / 100,0161 / 100,2727 / 100,6502 / 100,1281 / 100];

            var theAmount:int = rdCounts[timeline_slider.value];

            for (var i:int = 0; i < theAmount; ++i)
            {
                var rd = new red_dot();
                addChild( rd );

                rd.x = square_mc.x + Math.random() * square_mc.width;
                rd.y = square_mc.y + Math.random() * square_mc.height;
                var myTween:Tween = new Tween(rd,"x",Elastic.easeOut,square_mc.x,square_mc.x + Math.random() * square_mc.width,3,true);
       
            }

But adding removeChild()/removeChildAt() doesnt work, it removeChild doee remove rd if u use removeChild( rd ); but the slider breaks, and removeChildAt(); doesnt work all together..

Kenneth Kawamoto
Community Expert
Community Expert
May 20, 2011

You have some strange values in your Array... "0011 / 100" - why leading zeros? Anyway that will be treated as 0.11 and therefore 0 in terms of int value (your for loop does not run for that value).

That aside you may want to store your dots in an Array when you add to the display list, so that you can remove them easily when you need.