SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Eng: Mohammed Hussein1
Lecturer, and Researcher atThamar University
By Eng: Mohammed Hussein
mohammedhbi@thuniv.net
Output and trace in ActionScript 3.0
Eng: Mohammed Hussein2
 Define a variable and print it.
 Define for loop.
 Define a function to object
during an event.
Arrays In ActionScript 3.0
Eng: Mohammed Hussein3
 For example :
Using Mouse Events to Control Properties
Eng: Mohammed Hussein4
 Events are responsible for setting your scripts in motion, causing
them to execute.
 A button can be triggered by a mouse event, text fields react to
keyboard events—even calling your own custom functions.
 InActionScript 3.0, trapping events is simplified by relying on one
approach for all event handling, which is to use event listeners
regardless of the type of event or how it is used.
Events
Eng: Mohammed Hussein5
 What is addEventListener() function and its two parameters?
 What is Event.ENTER_FRAME?
 What does trace( ) function?
 In action script 3 look at the following code and give it a title name ?
Event Handling
Eng: Mohammed Hussein6
 Event handling is the process by which any sort of interactivity is
created in ActionScript 3.0.
 Event Handling system of AS3 are reacting to a mouse click, a
keyboard stroke, or any event happening in Flash which is divided into
the following sections:
1. Basic Event Handling Using the .addEventListener() method.
2. Unregistered Events Listeners using
the removeEventListener() method.
3. Working with EventTargets.
Event Listener
Eng: Mohammed Hussein7
 AnActionScript Event is any interaction happening in the Flash
environment, whether it was a mouse click, the movement of the
timeline to a new frame, the completion of the loading process of an
external asset, or any other occurrence.
 ActionScript can make any object react to any event by using an Event
Listener.
 An event listener is basically a function created with the very specific purpose
of reacting to an event.
 An object can react to an event using an event listener.This is done by using
the .addEventListenermethod.This method simply registers an Event
Listener and an Event to an object.
 The process described above is written in ActionScript using in the
format shown below:
myObject.addEventListener(Event, eventListenerFunction);
addEventListener() method
Eng: Mohammed Hussein8
Our Event Listener will obviously have to be specified by declaring
the function the same way any other function is declared in
ActionScript, the only difference is that the listener function must
have one argument to represent the event.
This event argument can have any identifier as its name, usually used
the letter 'e' for it as shown in the generalized code below:
myObject.addEventListener(Event, eventListenerFunction);
function eventListenerFunction (e:Event):void{
//ActionScript statements to be executed when the event happens.
}
Event can be registered
Eng: Mohammed Hussein9
 for example, if we want a graphical object placed on stage to act like a
button by reacting to a mouse click over it, we can simply register an event
and an event listener to it this way:
 For example, if you are using the Loader Class to load an external asset at
run time, you can perform a specific action only when the asset you are
trying to load finishes loading. For this, you will need to register for the
Event.COMPLETE as shown in the example below:
myButton.addEventListener(MouseEvent.CLICK, myClickReaction);
function myClickReaction (e:MouseEvent):void{
trace("I was clicked!");
}
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);
function startListener (e:Event):void{
trace("Loading Completed");
}
Unregistering Event Listeners
Eng: Mohammed Hussein10
 To unregister an event you can use the .removeEventListener() method in
the same exact way the .addEventListener() method is used.This method
requires specifying the object from which the event listener is to be
unregistered, the event to stop listening to, and the function that was
assigned to this specific event. Here is a generalized code on the usage of
this method:
myObject.removeEventListener(Event, eventListenerFunction);
For example, if an event listener function was registered to be triggered on
the entry of each new frame on the main timeline we would have registered
it this way:
this.removeEventListener(Event.ENTER_FRAME, loading);
Event Targets and Event Propagation
Eng: Mohammed Hussein11
 Depending on the event handled, an event would usually occur to a specific
object. For example, a click event will happen to a specific button and a load
complete event will happen to a specific instance of the loader class.
1. EventTarget with name movie, if we want an object to become hidden when
clicked, within the listener function to hide it this way:
2. EventTarget without specifying its name complex movies , we use the
keyword e.currentTarget because you want to reuse the same listener function
with more than one object. Now reuse this listener function for more than one
object without fear of breaking the code because of the smart reference to our
event target.
my_btn.addEventListener(MouseEvent.CLICK, hideMe);
function hideMe(e:MouseEvent):void{
my_btn.visible=false;
}
my_btn.addEventListener(MouseEvent.CLICK, hideMe);
function hideMe(e:MouseEvent):void{
e.currentTarget.visible=false;
}
my2_btn.addEventListener(MouseEvent.CLICK, hideMe);
Adding children
Eng: Mohammed Hussein12
 It is possible to refer to the children of an object to which an event
was registered using the keyword e.target (as opposed to
e.currentTarget) to refer directly to these objects.
 For example, if we have a MovieClip movie that has three buttons, we can
hide each of these buttons on its own when individually clicked by
registering ONE event listener to ONE object only, which is in this case
the display object container, i.e. the menu MovieClip, here is an example:
var myMenu_mc:MovieClip = new MovieClip();
myMenu_mc.addChild(my1_btn);
myMenu_mc.addChild(my2_btn);
myMenu_mc.addChild(my3_btn);
myMenu_mc.addEventListener(MouseEvent.CLICK, hideThisButton);
function hideThisButton(e:MouseEvent):void{
e.target.visible=false; }
MovieClip: myMenu_mc
has three buttons, we can hide
each of these buttons on its
own when individually
clicked.
The event listener function
registered with the actual
button clicked to e.target
Sound effects
13 Eng: Mohammed Hussein
Sound effect example
14 Eng: Mohammed Hussein
Playing sounds using ActionScript 3.0
Eng: Mohammed Hussein15
 Playing sounds using ActionScript 3.0 is not as simple as we hoped
it to be as it requires using more than one class to perform even the
simplest of tasks relating to sound such as pausing or changing the
sound volume.
 Introduction to Sound Related Classes.
 Playing an Internal Sound.
 Playing an External Sound.
 Stopping a Sound.
 Pausing a Sound.
 Changing SoundVolume.
Sound classes
 Sounds in ActionScript 3.0 are manipulated through the collaborative work of several
classes together.This format will provide you with greater control and the ability to micro
manage sounds. Here are the relevant classes related to sounds:
1. Sound Class -This is the main class in which a sound will actually reside.This class is
the starting point of any sound related program and is used to start playing a sound.
2. SoundChannel Class -A sound can be played through a sound channel which
provides additional controls over a sound object, the most basic of these additional
controls is the ability to stop the playback of a sound.
3. SoundTransform Class -This class is responsible for altering sound volume and
sound panning (manipulating the balance between the left and right speakers).
4. SoundMixer Class -This class has global control over all sounds played in the Flash
player. It's most basic function is to stop all playing sounds regardless of source.
16 Eng: Mohammed Hussein
Load sound
Eng: Mohammed Hussein17
 Two ways to load sound into flash:
1. First by using this code of AS3
2. Second one using import sound into
flash
Stop sound
Eng: Mohammed Hussein18
 To stop all sounds in your movie use this code:
Animated Speakers
Eng: Mohammed Hussein19
 Sound example
Animated Speakers and Equalizer Trick
(ASET) project
Eng: Mohammed Hussein20
 .stop() - this method stops the sound
playing through the channel.
 .position - this property is used to
retrieve the current playback
 position of the sound playing
through the channel.
 .soundTransform - this property is used
to set and retrieve sound
transformations such as volume
and panning.
(ASET) project steps
Eng: Mohammed Hussein21
1. Set Boolean value for buttons Play and Stop functions.
2. Create the sound object
3. Create the URL request that grabs the MP3 to play from your server or
hard drive.
4. Load the URL request into the Sound object
5. Create the SoundChannel variable.
6. Start playing the sound here in the channel variable
7. Set "isPalying" Boolean value to true because it is now playing.
8. Add listener to see when the song finishes to run function
[onPlaybackComplete] when it does Add listener to trigger
[onEnterFrame].
(ASET) project code
Eng: Mohammed Hussein22
 onEnterFrame
function run in loop
which can manipulate
our idea.
 onPlaybackComplete
function, used when
the song finishes to
stop channel playing.
Playing Video example
23 Eng: Mohammed Hussein
To add video into the Display List use
the addChild() method.
The .source property is used to specify the video to be played.
Applying a Skin to FLVPlayback Component
Eng: Mohammed Hussein
24
 The FLVPlayback Component is used when you want to play a video.
 To import the component to Library will require us to access the
Components Panel by going throughWindow>Component , look for the
FLVPlayback Component under theVideo category and then drag and drop
an instance of it on stage and then delete it.Which should store an instance
of the component in the Library.
 The graphical elements of skin are actually saved in a separate SWF file that
is loaded at run time by the main SWF movie. If you have the skin SWF file
available you simply set its URL as the value for a property called .
 Select your component on the stage and properties then skin.
Slide show
Eng: Mohammed Hussein25
 Give a title name
for this
ActionScript3 code?
Color
Eng: Mohammed Hussein26
 Give a title name
for this
ActionScript3
code?
 AS3 Changing
Colors
What is the output of this code?
Eng: Mohammed Hussein27
Output:
Venus,Earth,Mars
What is the output of this code?
Eng: Mohammed Hussein28
Output :
Maybe #0: I
Maybe #1: am
Maybe #2: Here
Maybe #3: Ok
Maybe # 3: Ok 4
Maybe # 3: Ok 4
What is the output of this code?
Eng: Mohammed Hussein29
Output :
80
What is the output of this code?
Eng: Mohammed Hussein30
Output :
10 15
11 16
11 16
After you Clicked the button and write the
outputs ?
Eng: Mohammed Hussein31
Output :
mohammed
ali
salim
What is the output of this code?
Eng: Mohammed Hussein32
Output :
-1
true
What is the output of this code?
Eng: Mohammed Hussein33
Output :
y: 33
x: 24
Correct the flowing code and write the
output ?
Eng: Mohammed Hussein34
What is the output of this code?
Eng: Mohammed Hussein35
Output :
Hello, Dr. Mohammed, nice to meet you.
Hello, saddam, nice to meet you.

Contenu connexe

Tendances

Event handling63
Event handling63Event handling63
Event handling63
myrajendra
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
kshyju
 

Tendances (17)

Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
Event handling
Event handlingEvent handling
Event handling
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Event handling63
Event handling63Event handling63
Event handling63
 
Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Event handling
Event handlingEvent handling
Event handling
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
 
Swing
SwingSwing
Swing
 
AWT
AWT AWT
AWT
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
 
Docimp
DocimpDocimp
Docimp
 

En vedette

02 greedy, d&c, binary search
02 greedy, d&c, binary search02 greedy, d&c, binary search
02 greedy, d&c, binary search
Pankaj Prateek
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences
Noushadur Shoukhin
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1
Mohammed Hussein
 

En vedette (20)

Lec3 Algott
Lec3 AlgottLec3 Algott
Lec3 Algott
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Whizle For Learners
Whizle For LearnersWhizle For Learners
Whizle For Learners
 
Multimedia lecture6
Multimedia lecture6Multimedia lecture6
Multimedia lecture6
 
Wireless lecture1
Wireless lecture1Wireless lecture1
Wireless lecture1
 
02 greedy, d&c, binary search
02 greedy, d&c, binary search02 greedy, d&c, binary search
02 greedy, d&c, binary search
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
 
Iteration, induction, and recursion
Iteration, induction, and recursionIteration, induction, and recursion
Iteration, induction, and recursion
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Comnet Network Simulation
Comnet Network SimulationComnet Network Simulation
Comnet Network Simulation
 
PHP
 PHP PHP
PHP
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1
 
Algorithm Analyzing
Algorithm AnalyzingAlgorithm Analyzing
Algorithm Analyzing
 
Multimedia Network
Multimedia NetworkMultimedia Network
Multimedia Network
 
Control system
Control systemControl system
Control system
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 

Similaire à Multimedia lecture ActionScript3

ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 

Similaire à Multimedia lecture ActionScript3 (20)

Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in android
 
Java gui event
Java gui eventJava gui event
Java gui event
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Actionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDEActionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDE
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
ACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptxACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptx
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 

Dernier

Dernier (20)

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

Multimedia lecture ActionScript3

  • 1. Eng: Mohammed Hussein1 Lecturer, and Researcher atThamar University By Eng: Mohammed Hussein mohammedhbi@thuniv.net
  • 2. Output and trace in ActionScript 3.0 Eng: Mohammed Hussein2  Define a variable and print it.  Define for loop.  Define a function to object during an event.
  • 3. Arrays In ActionScript 3.0 Eng: Mohammed Hussein3  For example :
  • 4. Using Mouse Events to Control Properties Eng: Mohammed Hussein4  Events are responsible for setting your scripts in motion, causing them to execute.  A button can be triggered by a mouse event, text fields react to keyboard events—even calling your own custom functions.  InActionScript 3.0, trapping events is simplified by relying on one approach for all event handling, which is to use event listeners regardless of the type of event or how it is used.
  • 5. Events Eng: Mohammed Hussein5  What is addEventListener() function and its two parameters?  What is Event.ENTER_FRAME?  What does trace( ) function?  In action script 3 look at the following code and give it a title name ?
  • 6. Event Handling Eng: Mohammed Hussein6  Event handling is the process by which any sort of interactivity is created in ActionScript 3.0.  Event Handling system of AS3 are reacting to a mouse click, a keyboard stroke, or any event happening in Flash which is divided into the following sections: 1. Basic Event Handling Using the .addEventListener() method. 2. Unregistered Events Listeners using the removeEventListener() method. 3. Working with EventTargets.
  • 7. Event Listener Eng: Mohammed Hussein7  AnActionScript Event is any interaction happening in the Flash environment, whether it was a mouse click, the movement of the timeline to a new frame, the completion of the loading process of an external asset, or any other occurrence.  ActionScript can make any object react to any event by using an Event Listener.  An event listener is basically a function created with the very specific purpose of reacting to an event.  An object can react to an event using an event listener.This is done by using the .addEventListenermethod.This method simply registers an Event Listener and an Event to an object.  The process described above is written in ActionScript using in the format shown below: myObject.addEventListener(Event, eventListenerFunction);
  • 8. addEventListener() method Eng: Mohammed Hussein8 Our Event Listener will obviously have to be specified by declaring the function the same way any other function is declared in ActionScript, the only difference is that the listener function must have one argument to represent the event. This event argument can have any identifier as its name, usually used the letter 'e' for it as shown in the generalized code below: myObject.addEventListener(Event, eventListenerFunction); function eventListenerFunction (e:Event):void{ //ActionScript statements to be executed when the event happens. }
  • 9. Event can be registered Eng: Mohammed Hussein9  for example, if we want a graphical object placed on stage to act like a button by reacting to a mouse click over it, we can simply register an event and an event listener to it this way:  For example, if you are using the Loader Class to load an external asset at run time, you can perform a specific action only when the asset you are trying to load finishes loading. For this, you will need to register for the Event.COMPLETE as shown in the example below: myButton.addEventListener(MouseEvent.CLICK, myClickReaction); function myClickReaction (e:MouseEvent):void{ trace("I was clicked!"); } my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener); function startListener (e:Event):void{ trace("Loading Completed"); }
  • 10. Unregistering Event Listeners Eng: Mohammed Hussein10  To unregister an event you can use the .removeEventListener() method in the same exact way the .addEventListener() method is used.This method requires specifying the object from which the event listener is to be unregistered, the event to stop listening to, and the function that was assigned to this specific event. Here is a generalized code on the usage of this method: myObject.removeEventListener(Event, eventListenerFunction); For example, if an event listener function was registered to be triggered on the entry of each new frame on the main timeline we would have registered it this way: this.removeEventListener(Event.ENTER_FRAME, loading);
  • 11. Event Targets and Event Propagation Eng: Mohammed Hussein11  Depending on the event handled, an event would usually occur to a specific object. For example, a click event will happen to a specific button and a load complete event will happen to a specific instance of the loader class. 1. EventTarget with name movie, if we want an object to become hidden when clicked, within the listener function to hide it this way: 2. EventTarget without specifying its name complex movies , we use the keyword e.currentTarget because you want to reuse the same listener function with more than one object. Now reuse this listener function for more than one object without fear of breaking the code because of the smart reference to our event target. my_btn.addEventListener(MouseEvent.CLICK, hideMe); function hideMe(e:MouseEvent):void{ my_btn.visible=false; } my_btn.addEventListener(MouseEvent.CLICK, hideMe); function hideMe(e:MouseEvent):void{ e.currentTarget.visible=false; } my2_btn.addEventListener(MouseEvent.CLICK, hideMe);
  • 12. Adding children Eng: Mohammed Hussein12  It is possible to refer to the children of an object to which an event was registered using the keyword e.target (as opposed to e.currentTarget) to refer directly to these objects.  For example, if we have a MovieClip movie that has three buttons, we can hide each of these buttons on its own when individually clicked by registering ONE event listener to ONE object only, which is in this case the display object container, i.e. the menu MovieClip, here is an example: var myMenu_mc:MovieClip = new MovieClip(); myMenu_mc.addChild(my1_btn); myMenu_mc.addChild(my2_btn); myMenu_mc.addChild(my3_btn); myMenu_mc.addEventListener(MouseEvent.CLICK, hideThisButton); function hideThisButton(e:MouseEvent):void{ e.target.visible=false; } MovieClip: myMenu_mc has three buttons, we can hide each of these buttons on its own when individually clicked. The event listener function registered with the actual button clicked to e.target
  • 13. Sound effects 13 Eng: Mohammed Hussein
  • 14. Sound effect example 14 Eng: Mohammed Hussein
  • 15. Playing sounds using ActionScript 3.0 Eng: Mohammed Hussein15  Playing sounds using ActionScript 3.0 is not as simple as we hoped it to be as it requires using more than one class to perform even the simplest of tasks relating to sound such as pausing or changing the sound volume.  Introduction to Sound Related Classes.  Playing an Internal Sound.  Playing an External Sound.  Stopping a Sound.  Pausing a Sound.  Changing SoundVolume.
  • 16. Sound classes  Sounds in ActionScript 3.0 are manipulated through the collaborative work of several classes together.This format will provide you with greater control and the ability to micro manage sounds. Here are the relevant classes related to sounds: 1. Sound Class -This is the main class in which a sound will actually reside.This class is the starting point of any sound related program and is used to start playing a sound. 2. SoundChannel Class -A sound can be played through a sound channel which provides additional controls over a sound object, the most basic of these additional controls is the ability to stop the playback of a sound. 3. SoundTransform Class -This class is responsible for altering sound volume and sound panning (manipulating the balance between the left and right speakers). 4. SoundMixer Class -This class has global control over all sounds played in the Flash player. It's most basic function is to stop all playing sounds regardless of source. 16 Eng: Mohammed Hussein
  • 17. Load sound Eng: Mohammed Hussein17  Two ways to load sound into flash: 1. First by using this code of AS3 2. Second one using import sound into flash
  • 18. Stop sound Eng: Mohammed Hussein18  To stop all sounds in your movie use this code:
  • 19. Animated Speakers Eng: Mohammed Hussein19  Sound example
  • 20. Animated Speakers and Equalizer Trick (ASET) project Eng: Mohammed Hussein20  .stop() - this method stops the sound playing through the channel.  .position - this property is used to retrieve the current playback  position of the sound playing through the channel.  .soundTransform - this property is used to set and retrieve sound transformations such as volume and panning.
  • 21. (ASET) project steps Eng: Mohammed Hussein21 1. Set Boolean value for buttons Play and Stop functions. 2. Create the sound object 3. Create the URL request that grabs the MP3 to play from your server or hard drive. 4. Load the URL request into the Sound object 5. Create the SoundChannel variable. 6. Start playing the sound here in the channel variable 7. Set "isPalying" Boolean value to true because it is now playing. 8. Add listener to see when the song finishes to run function [onPlaybackComplete] when it does Add listener to trigger [onEnterFrame].
  • 22. (ASET) project code Eng: Mohammed Hussein22  onEnterFrame function run in loop which can manipulate our idea.  onPlaybackComplete function, used when the song finishes to stop channel playing.
  • 23. Playing Video example 23 Eng: Mohammed Hussein To add video into the Display List use the addChild() method. The .source property is used to specify the video to be played.
  • 24. Applying a Skin to FLVPlayback Component Eng: Mohammed Hussein 24  The FLVPlayback Component is used when you want to play a video.  To import the component to Library will require us to access the Components Panel by going throughWindow>Component , look for the FLVPlayback Component under theVideo category and then drag and drop an instance of it on stage and then delete it.Which should store an instance of the component in the Library.  The graphical elements of skin are actually saved in a separate SWF file that is loaded at run time by the main SWF movie. If you have the skin SWF file available you simply set its URL as the value for a property called .  Select your component on the stage and properties then skin.
  • 25. Slide show Eng: Mohammed Hussein25  Give a title name for this ActionScript3 code?
  • 26. Color Eng: Mohammed Hussein26  Give a title name for this ActionScript3 code?  AS3 Changing Colors
  • 27. What is the output of this code? Eng: Mohammed Hussein27 Output: Venus,Earth,Mars
  • 28. What is the output of this code? Eng: Mohammed Hussein28 Output : Maybe #0: I Maybe #1: am Maybe #2: Here Maybe #3: Ok Maybe # 3: Ok 4 Maybe # 3: Ok 4
  • 29. What is the output of this code? Eng: Mohammed Hussein29 Output : 80
  • 30. What is the output of this code? Eng: Mohammed Hussein30 Output : 10 15 11 16 11 16
  • 31. After you Clicked the button and write the outputs ? Eng: Mohammed Hussein31 Output : mohammed ali salim
  • 32. What is the output of this code? Eng: Mohammed Hussein32 Output : -1 true
  • 33. What is the output of this code? Eng: Mohammed Hussein33 Output : y: 33 x: 24
  • 34. Correct the flowing code and write the output ? Eng: Mohammed Hussein34
  • 35. What is the output of this code? Eng: Mohammed Hussein35 Output : Hello, Dr. Mohammed, nice to meet you. Hello, saddam, nice to meet you.