Jothi Kannan
Jothi Kannan

Reputation: 3358

Dynamically draw rectangle between the Dragable objects in AS3

My aim is to highlight the area between the two dragable objects inpoint_mc and scrub_outpoint_mc, so i had created a rectangle between these points, i need to resize this rectangle based on the dragpoints, which indicates the distance between Inpoint and Outpoint, i tried my level best unfortunately i can acheive it

private function startScrubbingIN(_arg1:MouseEvent){
        trace("scrubBarIsMovingIN");
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScrubbingIN);
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.scrubBarIsMovingIN);
        this.scrubbing = true;
       var _local2:Rectangle = new Rectangle(this.controls_mc.progressBar_mc.x, this.controls_mc.inpoint_mc.y, 
            this.controls_mc.scrub_outpoint_mc.x-this.controls_mc.progressBar_mc.x, 0);
        // now we're limiting in point to current position of out point
        this.controls_mc.inpoint_mc.startDrag(false, _local2);

        this.controls_mc.addChild(_seekIndicator);
        _seekIndicator.graphics.beginFill(0x990000);
        _seekIndicator.graphics.drawRect(this.controls_mc.inpoint_mc.x, this.controls_mc.progressBar_mc.y, 
            this.controls_mc.scrub_outpoint_mc.x-this.controls_mc.progressBar_mc.x, 12);
        trace("_seekIndicator"+ _seekIndicator);
            // _seekIndicator.width = this.controls_mc.scrub_outpoint_mc.x+ this.controls_mc.inpoint_mc.y;
      }

it giving me the result as like the attached image

enter image description here

but the red rectangle need to be shrink itself between the 2 Points

Upvotes: 0

Views: 68

Answers (1)

Vesper
Vesper

Reputation: 18747

The rectangle should be redrawn only after you stop dragging, or when you move mouse while dragging. Don't forget to call _seekIndicator.graphics.clear() to delete old rectangle. And finally, use this.controls_mc.scrub_outpoint_mc.x and this.controls_mc.inpoint_mc.x for borders, because you're saying the rectangle should be between the in and out point MCs, while you use this.controls_mc.progressBar_mc.x in width.

private function scrubBarIsMovingIN(e:MouseEvent):void {
    // the startDrag dragged one of the sliders already
    // existing code skipped, if any
    _seekIndicator.graphics.clear();
    _seekIndicator.graphics.beginFill(0x990000);
    _seekIndicator.graphics.drawRect(this.controls_mc.inpoint_mc.x, this.controls_mc.progressBar_mc.y, 
        this.controls_mc.scrub_outpoint_mc.x-this.controls_mc.inpoint_mc.x, 12);
}

Should do.

Upvotes: 2

Related Questions