The problem is to search bit of text and replace any occurance of the searched string with something new, with `RegEx`

class and built-in `replace`

function of `String`

class it is very easy.

Continue reading

# Tag Archives: snippets

# JSFL – copy filters stack from Flash IDE into ActionScript 2 or 3 code

Hi,

working with designers one will always get into a problem of replication IDE based filters via code, it’s not a pleasant task nor quick as well, but what about if we could actually make it quick and pleasant? Well, that would be something.

# Rectangle class, equals method returns incorrect value

Hi,

recently I’ve used Rectangle’s equals() method and found that it incorrectly returns false when both rectangles are the same. Problem occurs when any of the properties of the Rectangle are NaN (not a number).

# useful use of switch block

Hi,

recently I have browsed through wonderfl.net and found unknown to me but useful use-case of *switch* block. The switch is selection control block and usually is used as follows:

Continue reading

# Rectangle with “sorted” edges

In some situation you would like to reassure that given Rectangle object have “top-down, left-right” order you can do it using following two snippets

this creates “normalized” copy of the given rectangle

/** * Takes rectangle as a parameter and returns new with sorted edges, i.e. (x=50, y=50, w=-100, h=-100) becomes (x=-50, y=-50, w=100, h=100). In other words it makes sure that rectangles top and left are smaller than bottom and right respectively. * * @param p_oRect * @return */ protected function normalizeRect(p_oRect:Rectangle):Rectangle { var nr:Rectangle = new Rectangle(); nr.top = Math.min(p_oRect.top, p_oRect.bottom); nr.bottom = Math.max(p_oRect.top, p_oRect.bottom); nr.left = Math.min(p_oRect.left, p_oRect.right); nr.right = Math.max(p_oRect.left, p_oRect.right); return nr; }

this modifies given rectangle directly

/** * Modifies the rectangle given in parameter and makes sure that edges are sorted, i.e. (x=50, y=50, w=-100, h=-100) becomes (x=-50, y=-50, w=100, h=100). In other words it makes sure that rectangles top and left are smaller than bottom and right respectively. * This method works directly on the object without making a copy. * @param p_oRectRef */ protected function normalizeRectV2(p_oRectRef:Rectangle):void { var _nSwap:Number; _nSwap = p_oRectRef.top; p_oRectRef.top = Math.min(_nSwap, p_oRectRef.bottom); p_oRectRef.bottom = Math.max(_nSwap, p_oRectRef.top); _nSwap = p_oRectRef.left; p_oRectRef.left = Math.min(_nSwap, p_oRectRef.right); p_oRectRef.right = Math.max(_nSwap, p_oRectRef.left); }