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

Change stroke width with AS3?

Contributor ,
Oct 12, 2009 Oct 12, 2009

So, I have a movie clip which consists of a filled vector circle with a stroke. Is it possible to increase/decrease the stroke to a specific thickness in pixels with actionscript whilst the swf is playing?

Thanks

T

TOPICS
ActionScript
5.1K
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

correct answers 1 Correct answer

Explorer , Oct 12, 2009 Oct 12, 2009

If you draw a circle dynamically using graphics API then its possible to chage the stroke by using lineStyle method.

But if that circle has already been drawn and placed in the stage, I don't think you can change it's stroke.

Can I ask, why don't you draw it dynamically using actionscript. It's so easy.

//make sure you import relavent apis

import flash.display.LineScaleMode;
import flash.display.CapsStyle;
import flash.display.JointStyle;

public var _cricleObj            :Sprite;

public var _lineSize   

...
Translate
Explorer ,
Oct 12, 2009 Oct 12, 2009

If you draw a circle dynamically using graphics API then its possible to chage the stroke by using lineStyle method.

But if that circle has already been drawn and placed in the stage, I don't think you can change it's stroke.

Can I ask, why don't you draw it dynamically using actionscript. It's so easy.

//make sure you import relavent apis

import flash.display.LineScaleMode;
import flash.display.CapsStyle;
import flash.display.JointStyle;

public var _cricleObj            :Sprite;

public var _lineSize            :Number    = 1;

//Now draw your circle

_cricleObj = new Sprite();

_cricleObj.graphics.lineStyle(_lineSize, 0xFFFF00, 1, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 3);

_cricleObj.graphics.beginFill(0xFF,1);
_cricleObj.graphics.drawCircle(0,0,50);
_cricleObj.graphics.endFill();

_cricleObj.addEventListener(Event.ENTER_FRAME, reDrawCircle);

public function reDrawCircle(e:Event):void
{
            _lineSize +=1;
            _cricleObj.graphics.clear();
            _cricleObj.graphics.lineStyle(_lineSize, 0xFFFF00, 1, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 3);
            _cricleObj.graphics.beginFill(0xFF,1);
            _cricleObj.graphics.drawCircle(0,0,50);
            _cricleObj.graphics.endFill();

  }

thats all.

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
Contributor ,
Oct 13, 2009 Oct 13, 2009
LATEST

That was the solution, thanks for that code example.

But I have now come across a much larger problem with getting the dynamic circle to appear correctly:

http://forums.adobe.com/thread/505778

T

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
Guest
Oct 12, 2009 Oct 12, 2009

You can use the graphics class to change the line style, you need to access the shape inside the movie clip in order to use the class.

you can access a shape in a movieclip by using getChildAt. then you can use the lineStyle function.

graphics.lineStyle(thickness, color, transparency).

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
Explorer ,
Oct 12, 2009 Oct 12, 2009

Although you use getChildAt to access a shape in a movieclip by using getChildAt. still you can't change it's linestyle.

if you use graphics.lineStyle(thickness, color, transparency) on that movieClip it can be used to draw a new graphic but can't alter the current one.

If I am wrong please show us an example with clear codes.

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
Guest
Oct 12, 2009 Oct 12, 2009

I think you are right getnaleen, thanks.

I don't know why, thought i did before but i just tried it and it doesn't work.

sorry..

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