Project Monocle a true profiler



2 Comments

Share




Can’t tell HOW am i excited about this new “monocle” profiler introduced by Thibault Imbert.
Needless to say anything. Just watch and enjoy.

Introducing Project “Monocle” from Thibault Imbert on Vimeo.

Flash Player + mouse right-click



2 Comments

Share




Flash Player 11.2 finally got the right-mouse button back!
Congrats! :)

Lee Brimelow posted a nice demo.

To achieve this, you’ll need to listen for the new MouseEvent.RIGHT_CLICK mouse event

Queue class (upd v.1.2)



5 Comments

Share




Sometimes you need to do a bunch of similar tasks at once (create similar display objects, render stuff, reindex pools etc), but often this may be a pain due to performance limits (which may result in poor user experience) and that’s where the queue pattern comes to the rescue. I’ve wrote a simple thought useful util for that purpose.

Play with the demo below (a simple IQueueItem implementation) or download the source (com.chargedweb.queue.*)


UPDATE: v.1.2 update + docs updated



A fast trick to lighten/darken colors



2 Comments

Share





Running example


/**
 * Scales r-g-b channels by 'scale' factor, having the r-g-b proportions saved
 * @param	color:uint		color to be scaled (i.e. lighten or darken)
 * @param	scale:Number	the scale factor (values -1 to 1) -1 = absolute dark; 1 = absolute light;
 * @return	uint			scaled color
 */
function scaleColor(color:uint, scale:Number):uint
{
	var r:int = (color & 0xFF0000) >> 16;
	var g:int = (color & 0x00FF00) >> 8;
	var b:int = color & 0x0000FF;
	r += (255 * scale)*(r/(r+g+b)); r = (r > 255) ? 255 : r; r = (r < 0) ? 0 : r;
	g += (255 * scale)*(g/(r+g+b)); g = (g > 255) ? 255 : g; g = (g < 0) ? 0 : g;
	b += (255 * scale)*(b/(r+g+b)); b = (b > 255) ? 255 : b; b = (b < 0) ? 0 : b;
	return (r << 16 &amp;amp;amp;amp; 0xff0000) + (g << 8 &amp;amp;amp;amp; 0x00ff00) + (b &amp;amp;amp;amp; 0x0000ff);
}

View the complete source code

Howdy mister JointStyle.MITER



5 Comments

Share






Do you like sharp border corners (miter ones)?
Well, i do, but adobe does not, probably… (watch the third square with JointStyle.MITER joints set)

ps: yeap, the issue can be fixed by setting the LineScaleMode.NORMAL, instead of the NONE, but what if i do need the NONE mode on?

Read more

as3scorm updated



No Comments

Share




Just a short post to let you know, that i’ve updated the as3scorm lib (simple course example added).
Might be useful to get started with the lib fast.

Copying objects bytearray vs for in loop



4 Comments

Share




I was curious, which of those would be quicker in the “copying objects” battle — bytearray / for in loop.
Foreseeing your possible thoughts, “yes” i do realize that those methods actually differ (bytearray copies the entire object, uses describeType etc), but still curiosity takes over :)
And, frankly, i was surprized with the results. See it for yourself.

Read more

Math.atan2 and zeros



2 Comments

Share




Keep in mind that


trace(0 === -0);			// true
trace(Math.atan2(0, 0));	// 0
trace(Math.atan2(0, -0));	// 3.141592653589793
trace(Math.atan2(-0, -0));	// -3.141592653589793

function posZero(n:Number) { if(n === 0) return Math.abs(n); }

SCORM 1.2/2004 as3 implementation



12 Comments

Share




as3 loves scorm

It’s been a while since i last posted in my blog thx to the holidays and the the enormous num of projects that’ve fallen down. One of my lastest projects was to build a swf course for an LMS using the SCORM standart. That’s when i’ve ran across Philip Hutchison’s blog and his SCORM project. After a few days of SCORM researches and running through the pipwerks SCORM solution, i came up with the idea to make an extention of it, which would fully implement SCORM 1.2 and 2004 “from the box” in the nearest future (currently a beta yet it works). [to be continued...]

So, here’s my version of the SCORM implementation for as3:

Download as3scorm at sourceforge (OS, MIT license as always)

UPDATE: added a new archive with a sample course

Might be useful:
SCORM 1.2
SCORM 2004 4th edition (and some more)
SCORM resourses, books, articles, tools etc
Adobe’s serialization as3corelib
Philip Hutchison’s aka pipwerks SCORM labs

ps: Philip thx A LOT for yr help! Btw if u have any scorm related questions, do not hesitate to contact either me or Philip

AlignUtil – align objects easily



12 Comments

Share




Recently i had to align tons of UIComponents with scale and even rotation defined. And so, i decided to write a small static class that would really facilitate my life. I called it AlignUtil. That’s it for now. All links are listed bellow. Hope it helps someone. Cheers ^_^

ps: btw i decided to switch my devs license to MIT, so from now on u r free to use the source codes for whatever u want purpose.

Online demo
Download the AlignUtil class

UPDATE: class updated to v.1.3

And here’s the source code (in case u r 2 lazy to download the archive):


////////////////////////////////////////////////////////////////////////////////
//
//  (c) 2011 Julius Loa | jloa[u know wha]chargedweb.com | http://chargedweb.com/labs/
//  All Rights Reserved.
//  license:	MIT {http://www.opensource.org/licenses/mit-license.php}
//  notice: 	just keep the header plz
//
////////////////////////////////////////////////////////////////////////////////

package com.chargedweb.utils
{
/** fp api **/
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.geom.Rectangle;
import flash.geom.Point;

/**
* <p>AlignUtil class - vertical/horizontal align DisplayObjects</p>
* @availability 	fp9 (flash/flex, as3)
* @version 		1.3
*
* <p>Class usage:</p>
* @example using parentalRelation set to "true" (aligning children inside the "parent")
* <listing version="3.0">
* import com.chargedweb.utils.AlignUtil;
*
* var btn:Button = new Button();
* btn.x = 100;
* btn.y = 100;
* btn.width = 100;
* btn.height = 30;
* btn.rotation = 30;
* addChild(btn);
*
* AlignUtil.setAlign(AlignUtil.H_CENTER, btn, this);
* AlignUtil.setAlign(AlignUtil.V_MIDDLE, btn, this);
* </listing>
*
* @example using parentalRelation set to "false" (aligning children according to another child on the same level)
* <listing version="3.0">
* import flash.display.Shape;
* import com.chargedweb.utils.AlignUtil;
*
* function createBox(w:Number, h:Number, r:Number):Shape
* {
* 	var sp:Shape = new Shape();
*	sp.graphics.beginFill(Math.random()*0xffffff);
*	sp.graphics.drawRect(0, 0, w, h);
*	sp.graphics.endFill();
*	sp.rotation = r;
*	return sp;
* }
*
* var a:Shape = createBox(200, 200, 45);
* a.x = 200; a.y = 100;
* addChild(a);
*
* var b:Shape = createBox(50, 20, -10);
* b.x = 50; b.y = 200;
* addChild(b);
*
* var c:Shape = createBox(120, 75, 150);
* c.x = 300; c.y = 200;
* addChild(c);
*
* // align 'b','c' according to 'a' (horizontal-left and vertical-top alignment)
* // horizontally
* AlignUtil.setAlign(AlignUtil.H_LEFT, b, a, false);
* AlignUtil.setAlign(AlignUtil.H_LEFT, c, a, false);
* // now vertically
* AlignUtil.setAlign(AlignUtil.V_TOP, b, a, false);
* AlignUtil.setAlign(AlignUtil.V_TOP, c, a, false);
* </listing>
*/
public class AlignUtil
{
/** Horizontal left alignment **/
public static const H_LEFT:String = "horizontalLeft";
/** Horizontal center alignment **/
public static const H_CENTER:String = "horizontalCenter";
/** Horizontal right alignment **/
public static const H_RIGHT:String = "horizontalRight";

/** Vertical top alignment **/
public static const V_TOP:String = "verticalTop";
/** Vertical middle alignment **/
public static const V_MIDDLE:String = "verticalMiddle";
/** Vertical bottom alignment **/
public static const V_BOTTOM:String = "verticalBottom";

/**
* Applies a specified alignment to the target DisplayObject
* @param	align:String				alignment mode (see the public constants defined above)
* @param	target:DisplayObject		target DisplayObject to align (according to the set alignment mode) @see flash.display.DisplayObject
* @param	parent:DisplayObject		the parent DisplayObject of the target one @see flash.display.DisplayObject
* @param	parentalRelation:Boolean	whether the "target" DisplayObject is a child of the "parent" or not @default true;
* @return	nothing
*/
public static function setAlign(align:String, target:DisplayObject, parent:DisplayObject, parentalRelation:Boolean = true):void
{
var a:String = align;
var t:DisplayObject = target;
var p:DisplayObject = parent;
var b:Rectangle = t.transform.pixelBounds;
var tp:Point = new Point();
var bp:Point;

/**
* @note 28/03/2011 :: bug fix for TextFields :: tip by Arindam Mojumder
* TextField.transform.pixelBounds return incorrect x/y coordinates (not the actual, but rather
* the one of the transform point) and the x/y are always 'zero' valued, so we make an exception for tfs
*/
if(t is TextField) b = t.getBounds(t.parent);

/** if parentalRelation is enabled, use local coordinates **/
if(parentalRelation)
{
bp = p.globalToLocal(new Point(b.x, b.y));
b.x = bp.x;	b.y = bp.y;
}else{
tp = new Point(p.transform.pixelBounds.x, p.transform.pixelBounds.y);
}

if(a == H_LEFT) t.x = (t.x > b.x) ? tp.x + t.x - b.x : tp.x;
if(a == H_CENTER) t.x = tp.x + int((p.width - b.width)/2 + t.x - b.x);
if(a == H_RIGHT) t.x = (t.x > b.x + b.width) ? tp.x + p.width : tp.x + p.width - (b.x + b.width - t.x);
if(a == V_TOP) t.y = (t.y > b.y) ? tp.y + t.y - b.y : tp.y;
if(a == V_MIDDLE) t.y = tp.y + int((p.height - b.height)/2 + t.y - b.y);
if(a == V_BOTTOM) t.y = (t.y > b.y + b.height) ? tp.y + p.height : tp.y + p.height - (b.y + b.height - t.y);
}
}
}

Older Entries