This is a translated page. The original can be found here: http://www.designscripting.com/2008/11/passing-arguments-to-event-handler-as3/comment-page-1/
Home » ActionScript 3.0 Home » ActionScript 3.0

Passing Arguments to Event Handler AS3: Argumentele pentru a trece Handler Eveniment AS3:

25 November 2008 2008-11-25 4 Comments 4 Comentarii

In AS2 we use Delegate class to pass arguments to event handlers and scoping event handlers. În AS2 vom folosi clasa Delegat pentru a trece la argumentele care operează eveniment şi ţeluri, care operează eveniment. But there is no Delegate class in AS3. Dar nu există nici clasa Delegat în AS3.

Still sending extra argument to event handlers is not a big deal. Totusi trimiterea argument suplimentar pentru a mîner eveniment nu este o afacere mare.

We are going to use one way of sending extra parameters to event handlers in actionscript 3.0, Vom utiliza o modalitate de a trimite în plus pentru a parametrilor de supervizare eveniment in ActionScript 3.0,

code: cod:

button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){handleClickEvent(e,"Home")}); button.addEventListener (MouseEvent.CLICK, funcţie (e: MouseEvent) (handleClickEvent (e, "Acasă ")});
function handleClickEvent(e:MouseEvent,str:String) { handleClickEvent funcţie (e: MouseEvent, str.: String) (
	trace("Argument :"+str,"- Event target :"+e.target.name); urme ("Argument:" + str, "- ţintă Eveniment:" e.target.name +);
} )

output: ieşire:
Argument :Home – Event target :button Argument: Home - Eveniment ţintă: buton

Here note, Aici notă,

We are adding event handler for button symbol. Suntem adăugând handler eveniment pentru simbolul buton. On click we call an inline function where inturn we are passing the MouseEvent and a parameter. Faceţi clic pe numim o funcţie de linie în cazul în care inturn suntem trece MouseEvent şi un parametru.

Simple is'nt it. is'nt simpla.

Cheers Noroc :)

VN:F [1.7.7_1013] VN: F [1.7.7_1013]
Rating: 10.0/ 10 (4 votes cast) Rating: 10.0 / 10 (4 voturi exprimate)
VN:F [1.7.7_1013] VN: F [1.7.7_1013]
Rating: +1 (from 3 votes) Rating: 1 (de la 3 voturi)
Passing Arguments to Event Handler AS3: 10.0 10 4 Trecerea la Argumentele Handler Eveniment AS3: 10.0 10 4
Translate this post Traduceţi acest post




4 Comments » 4 Comentarii »

  • Palash said: Palash a spus:

    Hi Hi
    This really helped me.I can pass arguments on panel onclick in flex 3 actionscript . Acest fapt a ajutat me.I pot trece argumentele pe panoul de onclick în Flex 3 ActionScript.
    Thanks Mulţumiri
    Palash Palash

    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 5.0/ 5 (1 vote cast) Rating: 5.0 / 5 (1 vot exprimate)
    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0 (from 0 votes) Rating: 0 (din 0 voturi)
  • David said: David a spus:

    Hmm. Hmm. but how do you remove the eventListener again? dar cum a face tu remove eventListener din nou?

    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0.0/ 5 (0 votes cast) Rating: 0.0 / 5 (0 voturi exprimate)
    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0 (from 0 votes) Rating: 0 (din 0 voturi)
  • Ricardo said: Ricardo a spus:

    Now, this is genius!! Acum, acest lucru este geniu!

    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0.0/ 5 (0 votes cast) Rating: 0.0 / 5 (0 voturi exprimate)
    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: +1 (from 1 vote) Rating: 1 (de la 1 vot)
  • DreadSquirrel said: DreadSquirrel a spus:

    Thanks mate! Multumesc amice! I actually knew that… i just forgot how to make inline functions in AS3 (and forgot they were called “inline”)… LOL! De fapt, am ştiut că ... am uitat cum să facă funcţii inline în AS3 (şi am uitat de ele au fost numite "inline") ... LOL!

    Passing arguments to event handlers this way is so much better for small apps, than making a custom Event class or dynamic class or any other similar overkill (which googling shows first as a way of dealing with the problem, sadly). Transmiterea argumentelor eveniment la care operează în acest mod este mult mai bine pentru aplicatii mici, decât a face o clasa Eveniment personalizat sau clasa dinamice sau orice alte nejustificată similare (care googling arată mai întâi ca o modalitate de a aborda această problemă, din pacate).

    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0.0/ 5 (0 votes cast) Rating: 0.0 / 5 (0 voturi exprimate)
    UN:F [1.7.7_1013] ONU: F [1.7.7_1013]
    Rating: 0 (from 0 votes) Rating: 0 (din 0 voturi)

Leave your response! Lăsaţi-vă de răspuns!

Add your comment below, or trackback from your own site. Adauga comentariu de mai jos, sau trackback de la propriul site-ul dumneavoastră. You can also subscribe to these comments via RSS. De asemenea, puteţi abona la aceste comentarii prin RSS.

Be nice. Fi frumos. Keep it clean. Pastreaza-l curat. Stay on topic. Stai pe subiect. No spam. Nu de spam.

You can use these tags: Puteţi folosi aceste tag-uri:
<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. Aceasta este o Gravatar weblog-activat. To get your own globally-recognized-avatar, please register at Gravatar . Pentru a-ti propria-a recunoscut la nivel global-avatar, vă rugăm să înregistraţi la Gravatar .

CAPTCHA Image
Actualizează Imagine