Razorberry’s Adobe Flash Blog

September 3rd, 2008

AS3: Removing duplicates from an array

Posted by Ash in Actionscript
Actionscript

Just for shiggles (yes, I said it.), removing duplicate items from an array in one line of ActionScript 3:

var arr:Array = ["a","b","b","c","b","d","c"];

var z:Array = arr.filter(function (a:*,b:int,c:Array):Boolean { return ((z ? z : z = new Array()).indexOf(a) >= 0 ? false : (z.push(a) >= 0)); }, this);

trace(z);

June 5th, 2008

Messing around with papervision again

Posted by Ash in Actionscript
Actionscript

Nothing too spectacular, but I threw together a new pointless animation for my front page.

See it here.

One day I will have enough varied content to warrant a menu or something.

Here is the source, for learning purposes. It won’t compile without a couple of files, but you can get the idea :)

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 :)

November 2nd, 2007

Converting html entities in AS3

Posted by Ash in Actionscript
Actionscript

I’m posting this here mainly because I always have to look it up. But maybe this post will help someone down the road.

Converting a string with html entities (such as &) to their respective symbols:

AS:


public function htmlUnescape(str:String):String
{
    return new XMLDocument(str).firstChild.nodeValue;
}

Converting a string so that it has html entities:

AS:


public function htmlEscape(str:String):String
{
    return XML( new XMLNode( XMLNodeType.TEXT_NODE, str ) ).toXMLString();
}
AS:


trace(htmlEscape(“ham & eggs”))// ham & eggs
trace(htmlUnescape(“ham & eggs”))// ham & eggs
July 27th, 2007

FP9 component pseudo-comparison

Posted by Ash in Actionscript
Actionscript

I thought I’d compile a little comparison of my Razor components (80% done!) vs the flex framework and the Flash CS3 components. I included just the components shown, but this is slightly unfair to Flex since it includes way more features in the framework that aren’t actually used here. Flash player 9 required for all of these movies except the first.
(more…)

May 30th, 2007

Slow progress

Posted by Ash in Actionscript
Actionscript

Last night I put some finishing touches to the Color Swatch/Color picker components for the Razor Component Set. It is mostly a rewrite of the old AS1 colour picker I made a few years ago. You can see the results below!

On another note, I’ve decided that the whole component set (AS 2 and 3 versions) will be released under the GPL, but you will be able to obtain a commercial license (I promise it will be very reasonably priced :D).

May 24th, 2007

Flash and Papervision3D abuse

Posted by Ash in Actionscript
Actionscript

I have these incredible tools at my disposal, and I produce this…

(more…)

May 22nd, 2007

FlashDevelop 3 alpha

Posted by Ash in Actionscript
Actionscript

I’ve been waiting for this one for a while: FlashDevelop 3.0.0 alpha was just released on the FlashDevelop forums.

http://www.flashdevelop.org/community/viewtopic.php?t=1436

October 27th, 2006

AS3 learning process: Stuff that wasn’t obvious #1

Posted by Ash in Actionscript
Actionscript

I finally have the chance to work on a real-world Actionscript 3 project (yeah, its been a long time coming). I realise that this post may be old news (and really pointless) to a lot of you, but I decided to write about things that weren’t immediately obvious to me while learning AS3.

The Loader class doesn’t dispatch events, but Loader.contentLoaderInfo does.
If you take a look at the API documentation for Loader.load(), you’ll notice that the different events dispatched after a load operation are listed, which lead me to think that the loader itself dispatches them. The fact is that you actually need to add your event listeners to Loader.contentLoaderInfo as shown in the example on that page.

In order to use flash.utils.getDefinitionByName(), your class has to actually be compiled into the swf.
Well, duh. Flash player will throw an error if it can’t find your class. This is easily solved by including a reference to the class in your source code somewhere.
private var myClass:Class = com.package.to.MyClass;

Removing a particular item from an array is easier!
array.splice(array.indexOf(obj),1);

Copying attributes of an xml node into an object is.. different.
var o:Object = new Object();
for each (var z:XML in node.@*)
{
o[String(z.name())] = z;
}

You can check if a DisplayObject is actually attached to a display list by checking the stage property.
If the stage property is null, it isn’t attached. This might seem obvious but if you’re trying to find out why something isn’t showing up.. the reason could be that you forgot to actually attach it with addChild().

In Flex Builder’s Actionscript 3 projects, mx classes aren’t immediately available.
You need to add the mx framework.swc to the project under Project->Properties->Flex Build Path->Library Path (tab)->Add SWC.. (button). The file is located at: ${FRAMEWORKS}/libs/framework.swc.

AS3 base types don’t always default to null.
Variables of certain base types such as Boolean and int are no longer ‘undefined’ when declared. This means you can no longer perform checks such as:
if (myBoolean == undefined) doSomething(); since boolean values default to false.
You can find a list of default values on this page in the documentation.

More to come..

August 22nd, 2006

Actionscript 2 Mystery of the day

Posted by Ash in Actionscript
Actionscript

I was just wondering if anyone could give me a good reason why

trace( (0 || 23) );

would trace ‘23′ instead of ‘true’ in AS2.

Bonus points for answers that contain mythical code-gnomes.

Next Page »
Macromedia XML News Aggregator