ActionScript 3.0 Slider doesn't continue when sliding to start
I made a slider to search trough my actionscript video. Maybe you'll understand better if you can see what i'm working on: http://www.stevevo.sin.khk.be/Website%202SDesign/ -> this is the link of the testserver where the website i'm building is running on. You'll see the huge banner in the center, rollover it an you'll see a slider and a pause/start button. The slider works great exept for 1 little thing. When you drag the slider to the utter left actionScript 3.0 will start the movie again (i asume), now drag to the right without interuptions and the slider won't move to the right as he should (all in one drag).
Why ain't it possible to first slide to the start and then continue sliding?
MY CODE:
very simple. You start dragging, the rectangle is the dragRestriction. The Movie stops. isDragging = true.
SearchBarSlider.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event:MouseEvent):void
{
var rect:Rectangle = new Rectangle(SearchBar.x + 3,
SearchBar.y,
SearchBar.width - 10,
0);
SearchBarSlider.startDrag(false, rect);
stop();
isDraging = true;
}
Again easy peasy. Drag stops. Movie starts to play again. isdragging = false;
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
SearchBarSlider.stopDrag();
play();
isDraging = false;
}
When the mouse moves when dragging the x-position of the slider will be converted to the right amount of frames. In between the 3 parts other lengths aply.
stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);
function fl_Drag(event:MouseEvent):void
{
if(isDraging == true) {
if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
} else if(SearchBarSlider.x - SearchBar.x + 3 >=开发者_Go百科 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
} else {
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
}
}
}
This event accurs at every frame when not dragging. But instead of converting the x-position of the slider to frames this will convert frames to x-positon of the slider.
stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);
function fl_frameEvent(e:Event):void
{
if(isDraging == false) {
if(currentFrame < 365){
SearchBarSlider.x = SearchBar.x + 3 + Math.round((currentFrame / 365) * 20);
} else if(currentFrame >= 365 && currentFrame < 685){
SearchBarSlider.x = SearchBar.x + 23 + Math.round(((currentFrame - 365) / 320) * 20);
} else {
SearchBarSlider.x = SearchBar.x + 43 + Math.round(((currentFrame - 685) / 465) * 20);
}
}
}
Does the second function really not occur when dragging? Do you remove it, or is it running at the same time? I think your enter_frame function and your mouse_move function are fighting each other. in your drag function add this:
stage.removeEventListener(Event.ENTER_FRAME, fl_frameEvent);
and in your drop function add this:
stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);
Another workaround, I noticed if you zoom way way in on the slider, if you come 99.9% of the way left, but don't quite line it up, it works as expected, so you could just adjust your draggable rectangle to leave just a tiny space on the left side.
SearchBar.x + 4
I actually fixed my own problem here's the solution.
stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);
function fl_Drag(event:MouseEvent):void
{
if(isDraging == true) {
if(SearchBarSlider.x - (SearchBar.x + 3) < 1){
} else if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
} else if(SearchBarSlider.x - SearchBar.x + 3 >= 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
} else {
gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
}
}
}
The problem was that when the gotoAndStop event accured at frame 1 the whole program restarted because at frame 1 the actions layer reinitiates the code. So the drag that was busy got ended. With the new piece of code the searchbar won't execute gotoAndStop(1);
精彩评论