简体   繁体   中英

AS3: Setting the movieclip's frame position as a variable

I've created a slider, and want to link the slider knob's X value to the frame position in a movieclip. It will work a little like a timeline bar. For example if the slider knob's x position is 12, it will change myMC to frame 12 etc..

Also, I don't understand how to create a variable for the myMC's frame position. But this is what I have so far.

var sliderValue:uint = mySlider.sliderKnob.x / 3;

addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
    sliderValue = mySlider.sliderKnob.x / 3;

    sliderValue.Number = myMC.frame;
}

It would help to see some context for this code, but it looks like what you're trying to do is something like this:

function onEnterFrame(event:Event):void
{
    sliderValue = mySlider.sliderKnob.x / 3;
    myMC.gotoAndStop(sliderValue);
}

I have no idea if this is actually correct as 3 appears to be an arbitrary number. In any case, the way you "set" the frame of a MovieClip is by calling the gotoAndStop function and passing either a frame number (as above), or a valid frame label.

You'll definitely want to do some error checking on sliderValue to make sure that it falls somewhere between 1 and myMC.totalFrames .

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