samedi 17 décembre 2016

Flash AS3 : Custom Sliders

I Am in need of some help making custom sliders, Sort of like the ones you would use for volume buttons, I have one but its not multi usable as soon as i add more than one the ones before stop working , and i dont think i can use local variables because i need to use event listeners for the scrubber to slide, All i am asking is if someone can please put a code for a multi usable slider with explanation on how its working so i can learn from it. i can show the code i am using right now but its probably useless

public function createSlider(x:Number, y:Number, parent:DisplayObjectContainer) : void {
        this.slider = new Sprite();
        this.slider.graphics.beginFill(0xFFFFFF);
        this.slider.graphics.drawCircle(x, y, 7);
        this.slider.graphics.endFill();
        this.bar = makeRoundedRect(x - 6, y - 6, 100, 11, 0xCCCCCC, 1, [10, 10, 10, 10]);
        parent.addChild(bar);
        parent.addChild(slider);

        this.slider.addEventListener(MouseEvent.MOUSE_OVER, sliderHover);
    }

    private function sliderHover(e:MouseEvent) : void 
    {
        this.slider.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);
    }
    private function sliderDown(e:MouseEvent) : void {
        this.slider.addEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
        this.slider.addEventListener(MouseEvent.MOUSE_UP, sliderDone);
        this.slider.addEventListener(MouseEvent.MOUSE_OUT, sliderDone);
    }

    private function sliderMove(e:MouseEvent) : void {
        this.slider.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);
        this.slider.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
        this.slider.startDrag(false, new Rectangle(0, slider.y, 90, 0));

    }
    private function sliderDone(e:MouseEvent) : void {
        this.temp_mouseCurX = Math.abs(this.slider.x + 10);
        trace(this.temp_mouseCurX);
        this.slider.stopDrag();
    }

its using a private variable which i know shouldnt be good for what i am trying to do , Any help is appreciated, And just comment and let me know if you need more information i will try to put as much as possible

Aucun commentaire:

Enregistrer un commentaire