Download presentation
Presentation is loading. Please wait.
Published byAmia King Modified over 11 years ago
1
Event Handling in flash Event: is an instantaneous occurrence usually triggered by user. هو احداث تقع فورا وتطلق عادة باستخدام المستخدم Event: is an instantaneous occurrence usually triggered by user. هو احداث تقع فورا وتطلق عادة باستخدام المستخدم Ex) clicking a button, moving mouse, clicking on a mouse Ex) clicking a button, moving mouse, clicking on a mouse Event Handling: writing action script that will be executed when the event occurs. هو كتابة الاكشن الذي سينفذ عند وقوع الحدث Event Handling: writing action script that will be executed when the event occurs. هو كتابة الاكشن الذي سينفذ عند وقوع الحدث Events can be handled by using Callback يمكن التعامل مع الحدث من خلال استدعاءه Events can be handled by using Callback يمكن التعامل مع الحدث من خلال استدعاءه Callback: function tied directly to a particular event. اقتران مربوط مباشرة مع حدث معين Callback: function tied directly to a particular event. اقتران مربوط مباشرة مع حدث معين
2
Event Handling in flash Ex) onEnterFrame = function() Ex) onEnterFrame = function(){ …. } Event handling examples: Event handling examples: 1. Handling button events: onPress: the event is triggered when a button is pressed. الحدث سيطلق عندما يكون الزر مضغوط onPress: the event is triggered when a button is pressed. الحدث سيطلق عندما يكون الزر مضغوط ex) btn.onPress = function() 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. الحدث سيطلق عند بعد الضغط ( أي بعد مانضغط على الزر onRelease: The event is triggered when a button is released after being pressed. الحدث سيطلق عند بعد الضغط ( أي بعد مانضغط على الزر ex) btn.onRelease = function() { … } ex) btn.onRelease = function() { … } onRollOver: The event is triggered when the mouse cursor moves over a button. الحدث سيطلق عند ما يكون مؤشر الماوس يتحرك فوق الزر onRollOver: The event is triggered when the mouse cursor moves over a button. الحدث سيطلق عند ما يكون مؤشر الماوس يتحرك فوق الزر Ex) btn.onRollOver = function() { … } Ex) btn.onRollOver = function() { … } 2. Handling mouse events: onMouseDown: it is triggered whenever the mouse button is pressed anywhere in the stage ex) onMouseDown = function() {} الحدث سيطلق عندما يضغط زرالماوس في أي مكان على المسرح 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 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 الحدث سيطلق كلما تحرك مؤشر الماوس فوق عنصر 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. Ex) This example shows how to drag a movie clip symbol from place to another using mouse events. 1. Create a new flash document 2. Insert a movie clip symbol onto the stage 3. Give it an instance name (m_shape) 4. In the action panel of the first frame: Declare a number variable (i) and initialize it to zero Declare a number variable (i) and initialize it to zero Add a (onMouseDown) handler that assigns one to (i) Add a (onMouseDown) handler that assigns one to (i)
6
Mouse Events Application Add a (onMouseMove) handler and insert the following code into it: 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) Add a (onMouseUp) handler that assigns zero to (i) Test the Program Test the Program To check whether the mouse button is being pressed To move the movie clip symbol with the mouse cursor
7
Handling Key Events Key events are handled by الاحداث التي تتناولها المفاتيح ( عاى الكيبورد ) Key events are handled by الاحداث التي تتناولها المفاتيح ( عاى الكيبورد ) 1) Creating an object to listen to key events انشاء كائن للاستماع إلى الأحداث 2) Associate the object with the key event types ربط كائن مع نوع من الاحداث 3) Register the object to start listening to key events تسجل الكائن للبدء في الاستماع للحدث Event types triggered when pressing keyboard keys: انواع الاحداث التي تطلق عند الضغط مفاتيح الكيبورد Event types triggered when pressing keyboard keys: انواع الاحداث التي تطلق عند الضغط مفاتيح الكيبورد A. onKeyDown: it is triggered whenever a keyboard button is clicked down الحدث سيطلق ( يبقى شغال ) طالما زر الكيبورد كان مضغوطا للاسفل B. 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: Ex) This example receives events from keyboard and prints the code of the pressed key: 1. Create a new flash document 2. In action panel of the first frame, type the following code:
9
Handling Key Events Some important functions found in class key: Some important functions found in class key: 1) Key.getAscii(): returns the ASCII code of the pressed alphanumeric character (s,r,5,3, ….) يرجع الاسكي كود للمفاتيح ( الارقام او الاحرف ) التي تضغط 2) 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. Write a flash application that moves a movie clip symbol using Keyboard.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.