Razorberry’s Adobe Flash Blog

January 28th, 2008

AS3 Dynamic Speech Bubble Snippet

Posted by Ash in Actionscript
Actionscript

The static method drawSpeechBubble in the file below uses the drawing API to draw a rounded rectangle based speech bubble with a dynamic point. The side the point is on moves depending on the relative position to the bubble. It looks best if you set the point to be fairly close to the actual rectangle.

Usage:

AS:


SpeechBubble.drawSpeechBubble(target:Sprite, rect:Rectangle, cornerRadius:Number, point:Point)

// Example:
var g:Graphics = graphics;

var m:Matrix = new Matrix();
m.createGradientBox(200,100,90*Math.PI/180,80,80);
g.clear();
g.lineStyle(2,0×888888,1,true);
g.beginGradientFill(GradientType.LINEAR, [0xe0e0e0, 0xffffff], [1,1], [1,0xff],m);
SpeechBubble.drawSpeechBubble(this, new Rectangle(80,80,200,100), 20, new Point(120,300));
g.endFill();

Sample (move mouse to change point position):

Download:
SpeechBubble.as

Apologies for any code messiness! I’m aware that you can create a dent in the corner.. it’s probably up to you to position the point sensibly so it doesn’t screw up :)

8 Responses to ' AS3 Dynamic Speech Bubble Snippet '

Subscribe to comments with RSS

  1. Angel Romero said,
    on January 29th, 2008 at 8:46 am

    Nice. Did you create this class yourself?

  2. Ash said,
    on January 29th, 2008 at 10:49 am

    Yes

  3. paranoio said,
    on February 3rd, 2008 at 3:18 pm

    :shock: just awesome

  4. on February 4th, 2008 at 12:27 pm

    :grin: Sweet effect.. Love simple ideas, that where genius starts.

  5. George Bones said,
    on February 9th, 2008 at 2:33 am

    Nice! And eerily similar to what something we’re using on our site (soon to launch) :smile:

    I had a question about your as3 color component, it’d be great to email if you have a chance,

  6. Drewb said,
    on June 9th, 2008 at 9:48 am

    Is there an AS2 version of this class? D

  7. Ash said,
    on June 9th, 2008 at 10:22 am

    Drewb: Theres really nothing as3 specific in the code, it should be a snap to convert.

    Change the first line of the function to var g:MovieClip = target;
    Then change the function header (so target is a MovieClip), and package stuff.

  8. on June 17th, 2008 at 1:15 pm

    great example. I will use this one in future

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:

Macromedia XML News Aggregator