This is a translated page. The original can be found here: http://www.designscripting.com/2008/10/introduction-to-as3-part2/
Home » ActionScript 3.0 Home » ActionScript 3.0

Introduction to AS3 – Part2 Introduzione alla AS3 - Parte 2

30 October 2008 30 Ottobre, 2008 One Comment Un commento

In this section we are going to cover In questa sezione stiamo andando a coprire

  • DOM3 event model Modello di eventi DOM3
  • Display list API Mostra lista API

I recommend going through the introduction to AS3 part 1 before reading part2. Vi consiglio di passare attraverso la introduzione alla parte AS3 1 prima di leggere part2.

DOM3 event model: modello DOM3 evento:

Document Object Model Level 3 event model (DOM3) provides a standard way of generating and handling event messages so that objects within applications can interact and communicate, maintaining their state and responding to change. Document Object Model Level 3 modello di eventi (DOM3) fornisce un modo standard di generare e gestire i messaggi di evento in modo che gli oggetti all'interno di applicazioni possono interagire e comunicare, mantenendo il loro stato e rispondere al cambiamento. Patterned after the World Wide Web Consortium DOM Level 3 Events Specification, this model provides a clearer and more efficient mechanism than the event systems available in previous versions of ActionScript. Modellato il World Wide Web Consortium DOM Level 3 Eventi specifica, questo modello fornisce un meccanismo più chiaro e più efficiente rispetto ai sistemi eventi disponibili nelle precedenti versioni di ActionScript.
The above text is from Flash Help. Il testo è dalla Guida di Flash. Explains clear about DOM. Spiega chiari su DOM.

SYNTAX FOR EVENT IN AS3: SYNTAX per l'evento in AS3:

function eventResponse(eventObject:EventType):void eventResponse funzione (EventObject: EventType): void
{ (
// Actions performed in response to the event go here. / / Le azioni eseguite in risposta all'evento andate qui.
} )
eventTarget.addEventListener(EventType.EVENT_NAME, eventResponse); eventTarget.addEventListener (EventType.EVENT_NAME, eventResponse); 

Let's see some practical examples. Vediamo alcuni esempi pratici.

IN AS2 IN AS2
// If we write a button event in Frame then it will be like this. / / Se scriviamo un evento pulsante nel fotogramma allora sarà così.
button.onRelease = function() button.onRelease = function ()
{ (
trace(”you Clicked me !!”) trace ("mi hai scattata!!")
} )

IN AS3 In AS3
There is no on() Event, onClipEvent, OnRelease Events in AS3. Non ci sono on () Evento, onClipEvent, Eventi onRelease in AS3.

function handleClickEvent( event : MouseEvent ) handleClickEvent funzione (evento: MouseEvent)
{ (
trace( "You Clicked Me !!" ); trace ("si è scelto me!");
} )
button.addEventListener( MouseEvent.CLICK, handleClickEvent ); button.addEventListener (MouseEvent.CLICK, handleClickEvent); 

EXPLANATION: SPIEGAZIONE:
Here eventTarget is button, to which we are adding event, Qui eventTarget è pulsante, a cui stiamo aggiungendo evento,
EventType is MouseEvent, if we are doing class type programming dont forget to import the package EventType è MouseEvent, se stiamo facendo dont classe tipo di programmazione dimentica di importare il pacchetto

import flash.events.MouseEvent; flash.events.MouseEvent importazione;

bcoz the events resides in this package. bcoz gli eventi risiede in questo pacchetto.
eventResponse is the function to be called when the event is triggered eventResponse è la funzione da chiamare quando l'evento viene attivato

NOTE : NOTA:
If we want to access the event target. Se vogliamo accedere al target dell'evento.
We can use event.target Possiamo usare event.target

Example Esempio

function handleClickEvent( event : MouseEvent ) handleClickEvent funzione (evento: MouseEvent)
{ (
trace( event.target );//outputs button name trace (event.target); / / stampa nome del pulsante
} ) 

button.addEventListener( MouseEvent.CLICK, handleClickEvent ); button.addEventListener (MouseEvent.CLICK, handleClickEvent);
In detailed tutorial we will see more about creating custom events. Nel tutorial dettagliato, vedremo più sulla creazione di eventi personalizzati.

NOTE: NOTA:
Some time the MovieClip or button inside the parent MovieClip may receive events to avoid to we can use. Qualche tempo MovieClip o il pulsante all'interno del MovieClip madre può ricevere gli eventi per evitare di noi può utilizzare.
button.mouseChildren = false; button.mouseChildren = false;

To enable handCursor after adding Events Per abilitare handCursor dopo l'aggiunta di Eventi

button.buttonMode = true; button.buttonMode = true;

Event Flow in AS3 Flusso di eventi in AS3
This is an important concept of how event flows when an event triggered. Questo è un concetto importante di come i flussi di evento attivato quando un evento.
Before that we will have little knowledge about Display List in AS3. Prima che avremo poca conoscenza Display List in AS3.

DISPLAY LIST: Visualizza la lista:
Each application built with ActionScript 3.0 has a hierarchy of displayed objects known as the display list. Ogni applicazione realizzata con ActionScript 3.0 presenta una gerarchia di oggetti visualizzati noto come l'elenco di visualizzazione. The display list contains all the visible elements in the application. L'elenco di visualizzazione contiene tutti gli elementi visibili nella domanda.
The events for the targets flow through hierarchy for objects in display list and triggered directly to object that's not in the display list. Gli eventi per gli obiettivi di flusso attraverso la gerarchia di oggetti nell'elenco di visualizzazione e innescato direttamente a oggetto che non è nell'elenco di visualizzazione.
The above definition is from flash help. La definizione di cui sopra è da aiutare flash.

For example event will be triggered directly to URLLoader objects. Per esempio evento sarà attivato direttamente URLLoader oggetti.

And for objects in display list, the event flows from stage to the target node. E per gli oggetti nell'elenco di visualizzazione, l'evento scaturisce dal palco al nodo di destinazione.
That phase of event travel from stage to target is known as Capture Phase. Tale fase del viaggio evento da stadio è noto come bersaglio fase di cattura.
When event reaches the target object it's known as Target Phase. Quando evento raggiunge il target oggetto è conosciuto come Phase Target.
After reaching the target event returns to the stage called Bubbling Phase. Dopo aver raggiunto l'evento di destinazione restituisce alla fase denominata bubbling.
Stage is the topmost object in the display list. Stage è l'oggetto più in alto nella lista di visualizzazione.
These three phases applicable to objects in display list. Queste tre fasi applicabile agli oggetti in lista di visualizzazione.

Still some events like enterframe and init events are exceptional. Ancora alcuni eventi come enterFrame ed eventi init sono eccezionali.

The event propagation can be handled by La propagazione di eventi possono essere gestiti da
STOPPING EVENT FLOW: ARRESTO EVENTO FLOW:

Event.stopPropogation() method to prevent event flow but only after the other event listeners of the target object to execute. Event.stopPropogation () per impedire il flusso di eventi, ma solo dopo gli ascoltatori altro evento del target oggetto di eseguire.

Event.stopImmediatePropogation() method to prevent event flow but does not allow other listeners of the target object to execute. Event.stopImmediatePropogation () per impedire il flusso di eventi, ma non consente altri ascoltatori del target oggetto di eseguire.

Display list API: Mostra lista API:
Each application built with ActionScript 3.0 has a hierarchy of displayed objects known as the display list. Ogni applicazione realizzata con ActionScript 3.0 presenta una gerarchia di oggetti visualizzati noto come l'elenco di visualizzazione. The display list contains all the visible elements in the application. L'elenco di visualizzazione contiene tutti gli elementi visibili nella domanda.
The events for the targets flow through hierarchy for objects in display list and triggered directly to object that's not in the display list. Gli eventi per gli obiettivi di flusso attraverso la gerarchia di oggetti nell'elenco di visualizzazione e innescato direttamente a oggetto che non è nell'elenco di visualizzazione.
The above definition is from flash help. La definizione di cui sopra è da aiutare flash.

The above definition is repeated intentionally. La definizione di cui sopra si ripete intenzionalmente.
These makes easy rendering of the objects in screen by flash player, Questi rende facile il rendering degli oggetti a schermo da Flash Player,
and easy traversal of objects in display list. e facile attraversamento di oggetti in lista di visualizzazione.
One of the new display object called Sprite. Uno dei display nuovo oggetto chiamato Sprite.
Its new light weight object, same as movieclip and does not has timeline. Il suo nuovo oggetto di peso leggero, la stessa MovieClip e non ha timeline.
Easy way to add created movieclip or other display objects like sprite is to use method modo semplice per aggiungere clip filmato creato o altri oggetti di visualizzazione, come sprite è quello di utilizzare il metodo
addChild() or addChildAt() addChild () o addChildAt ()
There is no methods like createEmptyMovieClip() and getNextHighestDepth() in AS3. Non ci sono metodi come createEmptyMovieClip () e getNextHighestDepth () in AS3. The depth will be added automatically if we use addChild() method and added to particular depth if we use addChildAt(); La profondità verrà aggiunto automaticamente se si usa metodo addChild () e aggiunto al particolare profondità, se usiamo addChildAt ();

CREATING DYNAMIC OBJECTS IN AS3: CREARE oggetti dinamici in AS3:

var _sprite : Sprite = new Sprite(); var _sprite: Sprite Sprite = new ();
with(_sprite) con (_sprite)
{ (
graphics.beginFill( 0xFF0000, 1); graphics.beginFill (0xFF0000, 1);
graphics.drawRect( 0, 0, 100, 100); graphics.drawRect (0, 0, 100, 100);
graphics.endFill(); graphics.endFill ();
} )
addChild(_sprite); addChild (_sprite); 

code Explanation: Spiegazione del codice:
As I done the code in frame we don't want to include the package, Come ho fatto il codice del telaio non si desidera includere il pacchetto,
Otherwise we need to import In caso contrario, abbiamo bisogno di importare
import flash.display.Sprite; flash.display.Sprite importazione;

we are using new keyword to instantiate sprite Object, and we are drawing one rectangle using the drawRect method of graphics object. stiamo usando parola chiave new per istanziare oggetti di sprite, e stiamo disegnando un rettangolo con il metodo drawRect di grafica dell'oggetto.
And finally adding to the display list. E infine aggiunge alla lista di visualizzazione. Using addChild Method. Utilizzando il metodo addChild.
Note after adding the display list the object will be rendered on the screen. Nota: dopo aver aggiunto l'elenco di visualizzazione l'oggetto sarà reso sullo schermo. And if u want to add the sprite created to another display object. E se la u desidera aggiungere la sprite creato per un altro oggetto di visualizzazione.
Instance.addChild( _sprite ); Instance.addChild (_sprite);

Here note we didn't specify the depth as we do in AS2. Qui di notare che non ha specificato la profondità come si fa in AS2. In AS3 will maintain the depth of its own. In AS3 manterrà la profondità del suo.
Suppose there are four display objects in DisplayList and if you add the child at depth 2, Supponiamo che ci sono quattro oggetti di visualizzazione in DisplayList e se si aggiunge il bambino in profondità 2,
Instance.addChildAt( _sprite, 2 ); Instance.addChildAt (_sprite, 2);

ACCESSING DYNAMICALLY CREATED OBJECT: ACCESSO creati dinamicamente OGGETTO:
The display object at 2 position will be moved to position 3 automatically. L'oggetto di visualizzazione in posizione 2 sarà spostato alla posizione 3 automaticamente.
If we want to access the objects added dynamically we need to use getChildAt() or getChildByName() methods to access the objects. Se vogliamo accedere agli oggetti aggiunti dinamicamente abbiamo bisogno di usare getChildAt () o getChildByName () per accedere agli oggetti.

var _sprite : Sprite = new Sprite(); var _sprite: Sprite Sprite = new ();
_sprite.name = "sprite" _sprite.name = "sprite"
with(_sprite) con (_sprite)
{ (
graphics.beginFill( 0xFF0000, 1); graphics.beginFill (0xFF0000, 1);
graphics.drawRect( 0, 0, 100, 100); graphics.drawRect (0, 0, 100, 100);
graphics.endFill(); graphics.endFill ();
} )
addChild(_sprite); addChild (_sprite); 

trace(” Accessing Dynamically created Object:::”,getChildByName(”sprite”).name); trace ("Accesso oggetti creati dinamicamente getChildByName :::", (" sprite "). nome);
// if we know the depth we can also access by / / Se conosciamo la profondità si può accedere anche da

trace(" Accessing Dynamically created Object:::",getChildAt(0).name); trace ("Accesso oggetti creati dinamicamente getChildAt :::", (0). nome); 

We can get the display object index by Siamo in grado di ottenere l'indice oggetto di visualizzazione da

getChildIndex( displayObject ); getChildIndex (DisplayObject); 

And removing the displayObject from the Display List using removeChildAt( index ); or removeChild(displayObject ); E la rimozione dei DisplayObject dall'elenco di visualizzazione utilizzando removeChildAt (indice), oppure removeChild (DisplayObject);
Here index is the depth of the display object in DisplayList. Qui indice è la profondità dell'oggetto di visualizzazione in DisplayList.
There is no SwapDepths() in AS3, instead we can use Non vi è alcun swapDepths () in AS3, invece si può usare

swapChildrenAt( index, index ); swapChildrenAt (index, indice);

or o
swapChildren( displayObject, displayObject ); swapChildren (DisplayObject, DisplayObject);

NOTE: if you create class type programs that extends MovieClip or Sprite. NOTA: se si creano programmi di tipo classe che estende MovieClip o Sprite.
You need to add the object of the class to DisplayList. È necessario aggiungere l'oggetto della classe per DisplayList.

Next Introduction to AS3 part3 Successivo Introduzione alla AS3 part3

Download Source files Fonte Scaricare file

VN:F [1.7.7_1013] VN: F [1.7.7_1013]
Rating: 0.0/ 10 (0 votes cast) Rating: 0.0 / 10 (0 voti)
VN:F [1.7.7_1013] VN: F [1.7.7_1013]
Rating: 0 (from 0 votes) Rating: 0 (da 0 voti)
Translate this post Traduci questo post




Leave your response! Lascia la tua risposta!

Add your comment below, or trackback from your own site. Aggiungi il tuo commento qui sotto, oppure trackback dal tuo sito. You can also subscribe to these comments via RSS. Puoi anche iscriverti a questi commenti via RSS.

Be nice. Sii gentile. Keep it clean. Keep it clean. Stay on topic. Rimani in argomento. No spam. No spam.

You can use these tags: È possibile utilizzare questi tag:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. Questo è un Gravatar abilitato weblog. To get your own globally-recognized-avatar, please register at Gravatar . Per ottenere il tuo globalmente riconosciute-avatar, registri prego a Gravatar .

CAPTCHA Image
Aggiorna Image