KEMBAR78
Multimedia lecture ActionScript3 | PDF
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.

Multimedia lecture ActionScript3

  • 1.
    Eng: Mohammed Hussein1 Lecturer,and Researcher atThamar University By Eng: Mohammed Hussein mohammedhbi@thuniv.net
  • 2.
    Output and tracein 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 ActionScript3.0 Eng: Mohammed Hussein3  For example :
  • 4.
    Using Mouse Eventsto 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: MohammedHussein6  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: MohammedHussein7  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: MohammedHussein8 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 beregistered 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 andEvent 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: MohammedHussein12  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 14Eng: Mohammed Hussein
  • 15.
    Playing sounds usingActionScript 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  Soundsin 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: MohammedHussein17  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: MohammedHussein18  To stop all sounds in your movie use this code:
  • 19.
    Animated Speakers Eng: MohammedHussein19  Sound example
  • 20.
    Animated Speakers andEqualizer 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 23Eng: 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 Skinto 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: MohammedHussein25  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 theoutput of this code? Eng: Mohammed Hussein27 Output: Venus,Earth,Mars
  • 28.
    What is theoutput 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 theoutput of this code? Eng: Mohammed Hussein29 Output : 80
  • 30.
    What is theoutput of this code? Eng: Mohammed Hussein30 Output : 10 15 11 16 11 16
  • 31.
    After you Clickedthe button and write the outputs ? Eng: Mohammed Hussein31 Output : mohammed ali salim
  • 32.
    What is theoutput of this code? Eng: Mohammed Hussein32 Output : -1 true
  • 33.
    What is theoutput of this code? Eng: Mohammed Hussein33 Output : y: 33 x: 24
  • 34.
    Correct the flowingcode and write the output ? Eng: Mohammed Hussein34
  • 35.
    What is theoutput of this code? Eng: Mohammed Hussein35 Output : Hello, Dr. Mohammed, nice to meet you. Hello, saddam, nice to meet you.