« How To Make an Image With Border
» How To Use FIVe3D In Flex

ActionScript, Components, How to, MXML

Continuing Image With Border

Andrei Ionescu | 12.06.08 | Comment?

Table of contents

  1. How To Make an Image With Border
  2. Continuing Image With Border

In the last article I explained how to create an image surrounded by border. That article is a start for fixing the issue: “image doesn’t have border style”.

Now I extended even more the new ImageBorder component to be able to center it horizontally and vertically and still be well displayed.

Modifications were made in updateDisplayList method these are:

  • added startX, startY, endX and endY - we set default value to them
  • x and y position reclaculated if there are set horizontalCenter and respectively verticalCenter
  • adjust startX and startY is horizontalAlign and verticalAlign are set to center the image

The code of updateDisplayList method is bellow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// overriding the update function
override protected function updateDisplayList(
    w:Number,h:Number):void
    {
    super.updateDisplayList(w,h);
    // clear graphics
    // we want only one rectangle
    graphics.clear();
    // set line style with with 0 and alpha 0
    graphics.lineStyle(0,getStyle('borderColor'),0,false);
    // draw rectangle
    graphics.beginFill(getStyle('borderColor'),getStyle('borderAlpha'));
    var thickness:Number = getStyle('borderThickness');
    var startX:Number;
    var startY:Number;
    var endX:Number;
    var endY:Number;
    startX = -thickness;
    endX = contentWidth + thickness*2;
    startY = -thickness;
    endY = contentHeight + thickness*2;
    if (getStyle("horizontalCenter") == undefined)
    {
        // adjust the position 
        // calculation based on initial position
        x = _recalX + thickness;
    }
    if (getStyle("horizontalAlign") == "center")
    {
        // adjust the position 
        // calculation based on initial position
        startX = Math.floor((width - contentWidth)/2) - thickness;
    }
    if (getStyle("verticalCenter") == undefined)
    {
        // adjust the position 
        // calculation based on initial position
        y = _recalY + thickness;
    }
    if (getStyle("verticalAlign") == "middle")
    {
        // adjust the position 
        // calculation based on initial position
        startY = Math.floor((height - contentHeight)/2) - thickness;
    }
    graphics.drawRect(startX,startY,endX,endY);
    graphics.endFill();
}

This are the modifications and see bellow how it is working. Both images are ImageBorder components one aligned top and left, one centered.

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride
ImageWithBorder_Part2_sources
ImageWithBorder_Part2




Tags: , , , , ,

This post was written by Andrei Ionescu

Views: 3209

related

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« How To Make an Image With Border
» How To Use FIVe3D In Flex