Archive for the ‘ Tutorials ’ Category

 
Friday, November 13th, 2009

You know what? I found the jump very easy and those guys at Adobe’s hq did a wonderful job on driving people into this new release of the Flex framework.
I’m not posting some code this time, just a link to a project which can be sooooooo helpful to take your dive: “Flex in a Week”.
Nothing hard, just take your time, your headphones and a good internet connection, drive your browser to http://www.adobe.com/devnet/flex/videotraining/flex4beta/index.html and start from the beginning…
If you’re not new to flex programming it will take you half a day to get into this new baby.

bye for now :)

Just posted the first episode of a cool tutorial on building RIAs with Cairngorm and Doctrine (a PHP ORM). This episode is about client only, next one will be about server side development.

tfmlogo

Have a huge coffee cup and take a read :)
Here’s the link

Recently I faced this problem: how to get if a Class is extending another one or implementing an interface?

this is the specific case:

?View Code ACTIONSCRIPT
function checkType(toCheck:Class,typeClass:Class=null,typeInterface:Class=null):Boolean
{
// if an instance of toCheck is a typeClass or a typeInterface
// return true
// else
// return false
}

The task is quite simple, the first solution would be get an instance of toCheck and use the is operator to actually check the type…but this would mean both a waste of resources and an “unwanted behaviour generator” (just think about a parser class instantiated without a real need or something like that).

Nope, that solution sucks.

Let’s try something better, let’s make the player inform us which is the toCheck class structure, let’s use describeType.

describeType is a wonderful function you can find in flash.utils package, it examines an untyped object and returns an xml document containing the description of that type (more details at adobe livedocs)…something like this:

NOTE: click on “view code” to see the real xml document, my wp is escaping tags chars <> …:\

<type name="flash.events::EventDispatcher" base="Class" isDynamic="true" isFinal="true" isStatic="true">
  <extendsClass type="Class"/>
  <extendsClass type="Object"/>
  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
  <factory type="flash.events::EventDispatcher">
    <metadata name="Event">
      <arg key="name" value="deactivate"/>
      <arg key="type" value="flash.events.Event"/>
    </metadata>
    <metadata name="Event">
      <arg key="name" value="activate"/>
      <arg key="type" value="flash.events.Event"/>
    </metadata>
    <extendsClass type="Object"/>
    <implementsInterface type="flash.events::IEventDispatcher"/>
    <constructor>
      <parameter index="1" type="*" optional="true"/>
    </constructor>
    <method name="willTrigger" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
      <parameter index="1" type="String" optional="false"/>
    </method>
    <method name="hasEventListener" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
      <parameter index="1" type="String" optional="false"/>
    </method>
    <method name="removeEventListener" declaredBy="flash.events::EventDispatcher" returnType="void">
      <parameter index="1" type="String" optional="false"/>
      <parameter index="2" type="Function" optional="false"/>
      <parameter index="3" type="Boolean" optional="true"/>
    </method>
    <method name="dispatchEvent" declaredBy="flash.events::EventDispatcher" returnType="Boolean">
      <parameter index="1" type="flash.events::Event" optional="false"/>
    </method>
    <method name="addEventListener" declaredBy="flash.events::EventDispatcher" returnType="void">
      <parameter index="1" type="String" optional="false"/>
      <parameter index="2" type="Function" optional="false"/>
      <parameter index="3" type="Boolean" optional="true"/>
      <parameter index="4" type="int" optional="true"/>
      <parameter index="5" type="Boolean" optional="true"/>
    </method>
    <method name="toString" declaredBy="flash.events::EventDispatcher" returnType="String"/>
  </factory>
</type>

As you can see in this EventDispatcher type description there are two nodes witch are fitting the task’s purposes:

<extendsClass> and <implementsInterface>

Those nodes are repeated for each class or interface in the given class (toCheck) chain of inheritance and they contain the qualified class name string of the extended\implemented class\interface.

In this case EventDispatcher extendsClass type=’Object’ and implementsInterface type=’flash.events::IEventDispatcher’ …quite clear right?:) Now, back to the implementation:

?View Code ACTIONSCRIPT
function checkType(toCheck:Class,typeClass:Class=null,typeInterface:Class=null):Boolean
{
	//gets the toCheck class type xml description
	var _typeXML:XML=describeType(toCheck);
	//gets the typeClass and typeInterface qualified class names
	var _result:Boolean=false;
	if (typeClass) {
		// if toCheck is a typeClass
		for each (var _extClass:XML in _typeXML.factory.elements('extendsClass')) {
			if (_extClass.@type==getQualifiedClassName(typeClass)) {
				_result=true;
				break;
			}
		}
	}
	// do the same for typeInterface but checking 'implementsInterface' node
	if (typeInterface) {
		for each (var _impInterface:XML in _typeXML.factory.elements('extendsClass')) {
			if (_impInterface.@type==getQualifiedClassName(typeInterface)) {
				_result=true;
				break;
			}
		}
	}
 
	return _result;
}

…and the task got done :)

stay tuned :)

 
Saturday, August 30th, 2008

Since it has been created i’ve been a fan of flash tracer extension, i really fell in love with that tool, but i noticed it slow down the browser and can even make it crash.

So, let’s open a trace logger on our terminal…

To do that the right command is “tail” which actually “[...]Print  the  last 10 lines of each FILE to standard output[...]” and the file to open is located in /Users/[your username]/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt

Then, let’s do something good and useful with that:

open your TextEdit, cmd+shift+T to switch to plain text, write down this one line command:

tail -f /Users/[your username]/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt

save the file as “flashtracer.sh” and use sh as file extension instead of txt.

then right click on the file, reach the “open with” menu and choose “terminal” application located inside utility folder. Note: it would be great if you set terminal as default application to open that file :)

ok, now everything’s ready; double click on flashtracer.sh and start tracing :)

Note: remember you’re in a shell now, so you can clear up the lines with cmd+K…

I hope it can be useful,

byez :)

 
Monday, June 2nd, 2008

I just found a very good tutorial by Senocular able to clarify every (or at least many) doubt and misunderstanding about practices to bring 3D effects in Flash.¬† Here’s the link http://www.kirupa.com/developer/actionscript/3dindex.htm

I don’t know if someone would be interested in this kind of experiments, there are many good projects that make 3D approach easier than build your own engine. However even if Papervision or Away3D let us make 3D content (..oh, i forgot to add flash 10 to this list :D ) I think it’s always better to understand what’s going on behind the scenes to better comprehend what’s the magic made of :)

Questo √® uno “microtutorial” piuttosto semplice sulle maschere (sono 2 linee di codice -.-) che per√≤ ho notato non essere troppo conosciuto.

Come creare un effetto “pila” o “occhio di bue”? o pi√π banalmente, come creare una maschera sfumata con flash8 o superiori?

  1. crea un movieclip da mascherare
  2. crea un altro movieclip contenente una forma con riempimento a gradiente nel quale almeno un colore abbia alpha minore di 100
  3. posiziona nello stage (fisicamente o via actionscript) i due clip: il mascherato e la maschera
  4. via actionscript imposta a true la propriet√† “cacheAsBitmap” di ciascun movieclip
  5. sempre via actionscript imposta la maschera del movieclip da mascherare (setMask in AS2 o mask in AS3)

ecco il risultato:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

questo il fla dell’esempio (CS3) Download Source

 
Sunday, December 30th, 2007

Ho trovato questo tutorial sul flex skinning direttamente sul developer network di yahoo.

tasty :D

http://developer.yahoo.com/flash/articles/flex-skinning.html

 
Thursday, November 22nd, 2007

Inauguro con questo tutorial la finora linda categoria Flex :D

Il breve tutorial che andrete a leggere verte su come fare un semplice drag n drop tra 2 list component in modo che gli item dell’uno fungano come target al drop degli elementi dell’altro (una possibile applicazione potrebbe essere quella di spostare dei files all’interno di una lista di cartelle).

Il drag n drop standard:

Flex permette di abilitare il drag n drop tra due component direttamente da mxml, senza tanti problemi, abilitando le proprietà dragEnabled e dropEnabled dei componenti desiderati.

Il risultato che si ottiene abilitando dragEnabled e dropEnabled è questo:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Droppando gli elementi della tilelist all’interno del datagrid questi verranno clonati ed aggiunti allo stesso datagrid. Le righe del datagrid non sono selezionabili, i nuovi elementi sono aggiunti prima o dopo i record gi√† presenti.

(more…)

Sarò breve e conciso (le ultime parole famose :) )

Il problema che andrò ad affrontare è il seguente:
come faccio a comunicare ad una classe il risultato di una funzione, o pi√π generalmente dei “dati” elaborati in maniera asincrona da un’altra classe istanziata nella mia classe di partenza?

Se i dati fossero elaborati e restituiti in diretta non ci si porrebbe il problema, esempio ne sono le classi di largo consumo come Math e Date (es: var mioint:int = Math.round(9.99999)).

Ma se volessi delegare (termine usato non a caso, visto i trascorsi di as2 :) ) a delle classi customizzate la mole di lavoro tipo delle routines di caricamento o qualcosa di simile?

Poniamo il caso di voler caricare una configurazione per la nostra applicazione\sito\game\… che risiede su un file cfg.xml.
Potremmo fare il tutto all’interno della document class cos√¨,

  1. creiamo una private var _cfgxml:XML
  2. nel costruttore andiamo a caricarci i dati con var myLoader:URLLoader = new URLLoader(new URLRequest(‘cfg.xml’));
  3. appioppiamo al loader un gestore di evento Event.COMPLETE a cui associamo il parsing dei dati myLoader.addEventListener(Event.COMPLETE,cfgParse);
  4. creiamo private function cfgParse(e:Evento) in cui istanziamo _cfgxml = new XML(e.target.data);

Ok, √® un’ipotesi plausibile, ma se questo nostro file richiedesse attenzioni particolari? o se semplicemente volessimo delegare ad altre classi le funzioni di parsing, di comunicazione con componenti, ecc ecc, solo per la soddisfazione di essere pi√π “puliti” nel codice…?

In actionscript 2 avremmo utilizzato Delegate passando come argomento la timeline (o l’istanza di classe) di riferimento. Ma in actionscript 3 “Delegate √® stat’ segheit” :D

Si rende quindi necessario passare la timeline\istanzadiclasse di riferimento come parametro per l’istanziazione della classe che elaborer√† i dati.

Esempio:

document class

?View Code ACTIONSCRIPT
private var _cfg:CFGManager;
 
public function Main(){
//costruttore
_cfg = new CFGManager(this);
_cfg.loadCFG();
 
}public function continuaMainClass(){}

classe richiamata dalla document class

?View Code ACTIONSCRIPT
private var _main:Main; //riferimento alla classe chiamante
public function CFGManager(m:Main){//costruttore
_main=m;//qui vado a memorizzare i riferimenti al main
}
 
public function loadCFG(){
//qui carico il mio xml di configurazione
//appioppo l'event listener per il caricamento
//e poi passo il tutto a parseCFG
}
private function parseCFG(e:Event){
//qui parso l'xml da e.target.data
//e poi faccio continuare l'esecuzione del main
_main.continuaMainClass();
}

Perfortuna non è nulla di così complesso :D

Per ottimizzare il tutto per√≤ sar√† opportuno non ricevere in ingresso un parametro fortemente tipizzato, ad esempio la classe CFGManager accetta in input solo parametri di tipo “Main”…se si vuole “astrarre” il codice, in modo da renderlo riutilizzabile sar√† opportuno che accetti potenzialmente qualsiasi tipo di dato, da DisplayObject all’estremo “*”…ma poi sono gusti :D

avevo detto che sarei stato breve, quindi alla prossima :D

 
Thursday, October 25th, 2007

phpBB è una delle piattaforme di forum free più diffuse nella rete.
Ha i vantaggi di essere completamente free e opensource, di essere di facile installazione, di avere svariati temi e mod che permettono facilmente di modificare praticamente tuto… ma c’√® anche l’altro lato della medaglia, un punto nettamente a sfavore di phpBB √® la spam e gli spambot.

Ma perch√® darla vinta agli spammers cambiando l’engine del forum (passando a vBulletin o a chiss√† quale altro) o perseverando nell’eliminare gli utenti fasulli uno ad uno?

Ecco qualche accorgimento per diventare uno

SpamFucker

e godersi il proprio forum phpBB gratuito…

(more…)