[ NikO ]

You are here: Welcome » blog

Concours Créative Mediabox

Mediabox lance un nouveau défi à toute la communauté créative, petits ou grands, illustrateurs confirmés ou gribouilleurs passagers, bref à tout le monde (pour peu bien sûr que vous soyez inscrit sur le forum.

Ce défi est un concours mensuel qui vous permettra d’engranger des points selon vos performances, d’échanger ces points contre des licences Adobe, des tee-shirts... mais aussi de faire parti du jury. Bref une aventure humaine et créative ( Voir réglement ).

Le 1er concours se déroule du 1er au 20 Décembre, avec pour theme “Les difficultés de l’invisibilité...”.

Pour plus d’informations, jetez un oeil au topic concerné

→ Read more...

Tags : ,
· 2007/12/01 12:43 · 1 Comment

logger flex for firebug

 
package nc.logging
{
	import mx.logging.*;
	import mx.formatters.DateFormatter;
	import flash.external.ExternalInterface;
	import flash.system.System;
	import flash.system.Capabilities;
 
	public class FirebugTarget extends AbstractTarget implements ILoggingTarget
	{
		private static var logger : ILogger = Log.getLogger('nc.logging.FirebugTarget');
		
		public static var enableTimeStamp:Boolean = true;
		private static const dateFormat:String = "YYYY-MM-DD HH:NN:SS";
		
		private var _df:DateFormatter;
		
		public function FirebugTarget () : void
		{
			_df= new DateFormatter();
			_df.formatString = dateFormat;
			super();
		}
		
		public override function logEvent(e : LogEvent) : void 
		{
			var pt : String = Capabilities.playerType
			if (pt == 'PlugIn' || pt == 'ActiveX')
			{
				var cmd : String;
				switch (e.level)
				{
					case LogEventLevel.ALL :
						cmd = "console.log"
						break;
					case LogEventLevel.DEBUG :
						cmd = "console.debug"
						break;
					case LogEventLevel.ERROR :
						cmd = "console.error"
						break;
					case LogEventLevel.FATAL :
						cmd = "console.fatal"
						break;
					case LogEventLevel.INFO :
						cmd = "console.info"
						break;
					case LogEventLevel.WARN :
						cmd = "console.warn"
						break;
				}
				if (cmd)
				{
					var a : Array = new Array ();
					if (enableTimeStamp) 
					{
						a.push('['+_df.format(new Date())+'] '+e.message); 
					} else {
						a.push(e.message); 
					}
					ExternalInterface.call.apply(ExternalInterface,[cmd].concat(a));
				}
			}
		}
	}
}

→ Read more...

Tags : ,
· 2007/09/27 18:27 · 1 Comment

bindable singleton proxy flex

An easy way to have a pseudo bindable proxy with typed accessor in flex/as3 :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="vertical"
	creationComplete="{onComplete(event)}">
	<mx:Script>
		<![CDATA[
			import nc.examples.PseudoSingletonProxy;
			
			[Bindable]
			protected var o1 : PseudoSingletonProxy;
			
			[Bindable]
			protected var o2 : PseudoSingletonProxy;
			
			
			import mx.events.FlexEvent;
			private function onComplete (e:FlexEvent) : void
			{
				removeEventListener(FlexEvent.CREATION_COMPLETE,onComplete,false);
				o1 = new PseudoSingletonProxy ();
				o2 = new PseudoSingletonProxy ();
			}
			
			private function onClick1(e:MouseEvent) : void
			{
				o1.myVar = Math.random().toString();
			}
			
			private function onClick2(e:MouseEvent) : void
			{
				o2.myVar = Math.random().toString();
			}
		]]>
	</mx:Script>
	
	<mx:HBox 
		width="100%"
		>
		<mx:Label 
			text="o1.myVar" 
			/>
		<mx:Label 
			text="{o1.myVar}" 
			/>
	</mx:HBox>
	
	<mx:HBox 
		width="100%"
		>
		<mx:Label 
			text="o2.myVar" 
			/>
		<mx:Label 
			text="{o2.myVar}" 
			/>
	</mx:HBox>
	
	<mx:HBox width="100%">
		<mx:Button 
			label="Change o1.myVar" 
			click="{onClick1(event)}"
			/>
		<mx:Button 
			label="Change o2.myVar" 
			click="{onClick2(event)}"
			/>
	</mx:HBox>
	
</mx:Application>
package nc.examples
{
	import flash.events.IEventDispatcher;
	import flash.events.Event;
	import mx.managers.ISystemManager;
	import mx.utils.ObjectProxy;
	import flash.events.EventDispatcher;
	import mx.events.PropertyChangeEvent;
	
	[Mixin]
	[Bindable('propertyChange')]
	public class PseudoSingletonProxy implements IEventDispatcher
	{
		private static var __oProxy : ObjectProxy;
		private static var __oED : EventDispatcher
		
		private var _oProxy : ObjectProxy;
		
		public function PseudoSingletonProxy () : void
		{
			_oProxy = __oProxy;
			if (!_oProxy.hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
			{
				_oProxy.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,
									onProxyPropertyChanged,
									false,
									0,
									true);
			}
		}
		
		public function set myVar (value:String) : void
		{
			_oProxy.myVar = value;
		}
		
		public function get myVar () : String
		{
			return _oProxy.myVar;
		}
		
		private function onProxyPropertyChanged (e:PropertyChangeEvent) : void
		{
			__oED.dispatchEvent(e);
		}
		
		public static function init (value:ISystemManager) : void
		{
			__oProxy = new ObjectProxy ();
			__oED = new EventDispatcher ();
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return __oED.hasEventListener(type);
		}
		
		public function willTrigger(type:String):Boolean
		{
			return __oED.willTrigger(type);
		}
		
		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0.0, useWeakReference:Boolean=false):void
		{
			__oED.addEventListener(type,listener,useCapture,priority,useWeakReference);
		}
		
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			__oED.removeEventListener(type,listener,useCapture);
		}
		
		public function dispatchEvent(event:Event):Boolean
		{
			return __oED.dispatchEvent(event);
		}
		
	}
}

→ Read more...

Tags : ,
· 2007/09/27 18:23 · 6 Comments

clone an object in as3

Easy to do :

package nc.utils
{
	import flash.utils.ByteArray;
	import flash.net.registerClassAlias;
	import flash.utils.getQualifiedClassName;
	import flash.net.getClassByAlias;
	import flash.utils.describeType;
	import flash.utils.getDefinitionByName;
	
	public class ObjectUtils
	{
		/**
		*  Clone an Object
		*
		*  @param object The Object to clone (Object is not a part of the displayList
		*  and object don't need arguments in constructor)
		*
		*  @param type The Class of the Object to clone.
		*
		*  @return a clone of Object
		*/
		public static function clone (object:*,type:Class) : *
		{
			var alias : String = getQualifiedClassName(object).split('::').join('.');
			try
			{
				getClassByAlias(alias);
			} catch (e:ReferenceError)
			{
				registerClassAlias(alias,type);			
			}
			
			var x : XML = describeType(object),
				childrens : XMLList = x.children(),
				l : int = childrens.length(),
				i : int = -1,
				xClass : XML;
			while (++i<l)
			{
				xClass = childrens[i] as XML;
				registerAll(xClass);
			}
			var r : ByteArray = new ByteArray ();
			r.writeObject(object);
			r.position = 0;
			var clone : *;
			try
			{
				clone = r.readObject();
				return clone as type;
			} catch (e:TypeError)
			{	
				trace (e);
			}
			return null;
		}
		
		private static function registerAll (x:XML) : void
		{
			var a : Array = ['type','declaredBy','returnType'],
				l : int = a.length,
				i : int = -1,
				raw : String,
				aSplit : Array,
				type : Class,
				alias : String;
			while (++i<l)
			{
				raw = x.attribute(a[i] as String).toString();
				if (raw.indexOf('::') != -1)
				{
					aSplit = raw.split('::');
					if (aSplit.length == 2)
					{
						alias = aSplit.join('.');
						type = getDefinitionByName(alias) as Class;
						try 
						{
							getClassByAlias(alias)
						} catch (e:ReferenceError)
						{
							trace ('Register --> '+alias+' as '+type);
							registerClassAlias(alias,type);
						}
					}
				}
			}
		}
	}
}

→ Read more...

Tags :
· 2007/07/20 21:00 · 14 Comments

mediabox

Un nouveau channel sur freenode viens d’ouvrir #mediabox, je vous y attends :)

→ Read more...

Tags :
· 2007/07/19 14:17 · 0 Comments

Older entries >>