1 / 11

Event Handling in flash

Event Handling in flash. Event: is an instantaneous occurrence usually triggered by user. هو احداث تقع فورا وتطلق عادة باستخدام المستخدم Ex) clicking a button, moving mouse, clicking on a mouse

Download Presentation

Event Handling in flash

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Event Handling in flash • Event: is an instantaneous occurrence usually triggered by user.هو احداث تقع فورا وتطلق عادة باستخدامالمستخدم • Ex) clicking a button, moving mouse, clicking on a mouse • Event Handling: writing action script that will be executed when the event occurs.هو كتابة الاكشن الذي سينفذ عند وقوع الحدث • Events can be handled by using Callbackيمكن التعامل مع الحدث من خلال استدعاءه • Callback: function tied directly to a particular event.اقتران مربوط مباشرة مع حدث معين

  2. Event Handling in flash • Ex) onEnterFrame = function() { …. } • Event handling examples: • Handling button events: • onPress: the event is triggered when a button is pressed.الحدث سيطلق عندما يكون الزر مضغوط • ex) btn.onPress = function() { …. } Code written inside function is tied to the event (onEnterFrame) الكود المكتوب داخل الاقتران مربوط مع الحدث • Code written here will be executed when (btn) is pressed • This callback function is written in the first frame btn: is the instance name of a button

  3. Event Handling in flash • onRelease: The event is triggered when a button is released after being pressed.الحدث سيطلق عند بعد الضغط (أي بعد مانضغط على الزر • ex) btn.onRelease = function() {…} • onRollOver: The event is triggered when the mouse cursor moves over a button. الحدث سيطلق عند ما يكون مؤشر الماوس يتحرك فوق الزر • Ex) btn.onRollOver = function() {…} • Handling mouse events: • onMouseDown: it is triggered whenever the mouse button is pressed anywhere in the stage ex) onMouseDown = function() {}الحدث سيطلق عندما يضغط زرالماوس في أي مكان على المسرح

  4. Event Handling in flash • onMouseUp: it is triggered whenever the mouse button is released after being pressed ex) onMouseUp=function() { … } • onMouseMove: it is triggered whenever the mouse cursor moves over a componentالحدث سيطلق كلما تحرك مؤشر الماوس فوق عنصر ex) onMouseOver=function() { … }

  5. Mouse Events Application • Ex) This example shows how to drag a movie clip symbol from place to another using mouse events. • Create a new flash document • Insert a movie clip symbol onto the stage • Give it an instance name (m_shape) • In the action panel of the first frame: • Declare a number variable (i) and initialize it to zero • Add a (onMouseDown) handler that assigns one to (i)

  6. Mouse Events Application • Add a (onMouseMove) handler and insert the following code into it: if(i==1) { m_shape._x=_xmouse; m_shape._y=_ymouse; } • Add a (onMouseUp) handler that assigns zero to (i) • Test the Program To move the movie clip symbol with the mouse cursor To check whether the mouse button is being pressed

  7. Handling Key Events • Key events are handled byالاحداث التي تتناولها المفاتيح(عاى الكيبورد) • Creating an object to listen to key eventsانشاء كائن للاستماع إلى الأحداث • Associate the object with the key event typesربط كائن مع نوع من الاحداث • Register the object to start listening to key eventsتسجل الكائن للبدء في الاستماع للحدث • Event types triggered when pressing keyboard keys:انواع الاحداث التي تطلق عند الضغط مفاتيح الكيبورد • onKeyDown: it is triggered whenever a keyboard button is clicked downالحدث سيطلق(يبقى شغال)طالما زر الكيبورد كان مضغوطا للاسفل • onKeyUp: it is triggered whenever a keyboard button is released الحدث سيطلق(يبقى شغال)طالما زر الكيبورد كان مضغوطا للاعلى(أي غير مضغوط)

  8. Handling Key Events • Ex) This example receives events from keyboard and prints the code of the pressed key: • Create a new flash document • In action panel of the first frame, type the following code:

  9. Handling Key Events • Some important functions found in class key: • Key.getAscii(): returns the ASCII code of the pressed alphanumeric character (s,r,5,3,….)يرجع الاسكي كود للمفاتيح (الارقام او الاحرف) التي تضغط • Key.getCode(): returns the code of the pressed non-alphanumeric keys (shift, ctrl, tab…) يرجع الاسكي كود للمفاتيح (غير ارقام والاحرف مثل سباس وشفت وكنترول واسهم الاتجاهات) التي تضغط

  10. Handling Key Events var i:Object = new Object(); i.onKeyDown = function() { trace(Key.getCode()); } Key.addListener(i); Creating an object to listen to key events Associate the object with the key event types This code will be executed when pressing on any keyboard key Register the object to start listening to key events

  11. Excersice • Write a flash application that moves a movie clip symbol using Keyboard.

More Related