Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 draw custom line

Explorer ,
Jun 23, 2014 Jun 23, 2014

I am trying to create custom line or brushes that will be used to color in.

If I have 2 different movieclips, eg:

1. star

2. oval

How can i draw a line made out of these movieclips

I tried to addChild movieclips on the mouse move or on-enterframe but its not quick enough and leaves spaces in between.

I originally used a lineStyle, but now I need to replace that with a specific movieclip shape.

Any thoughts are welcome.

P

TOPICS
ActionScript
551
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 23, 2014 Jun 23, 2014
LATEST

import flash.display.MovieClip;

import flash.events.MouseEvent

import flash.geom.Point;

var startPoint:Point = new Point();

var endPoint:Point = new Point();

stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);

stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);

stage.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);

function downHandler(e:MouseEvent):void {

    startPoint.x = mouseX;

    startPoint.y = mouseY;

}

function upHandler(e:MouseEvent):void {

    endPoint.x = mouseX;

    endPoint.y = mouseX;

}

function moveHandler(e:MouseEvent):void {

    //1.delete all stars you previously added to the displaylist

    ...

    //2.get the endPoint

    endPoint.x = mouseX;

    endPoint.y = mouseX;

    var s:Star = new Star();

    drawObjectLineFromTo(s, startPoint, endPoint);

}

function getDistance(_p1:Point,_p2:Point):Number{

    //use trigonometry to get the distance

    ...

}

function drawObjectLineFromTo(_mc:MovieClip,_p1:Point,_p2:Point):void{

    var d:Number = getDistance(_p1, _p2);

    var objectNumber:int = Math.round(d /_mc.width);

    for (var i:int = 0; i < objectNumber; i++) {

        //with a MovieClip exported to Star in your Library

        var s:Star = new Star();

        addChild(s);

        //use trigonometry to place your stars evenly distributed betweeen _p1, _p2

        ...

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines