Multimedia lecture ActionScript3

671 views

Published on

Adobe Action Script 3.0 code

Published in: Education, Technology, Business
2 Comments
1 Like
Statistics
Notes
  • اشكرك مهندس رضوان وهذا العمل مضاف ايضاً الى مشاركة جهودكم
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • لا غرابه في ان تنال هذه المحاضره وهذا الترتيب والتسلسل الراقي لمواضيع المحاضره الثالثه في الاكشن فلاش .... لان الي اعدها ورتبها هو الاستاذ القدير محمد حسين الحبيشي فشكرا له علي هذ المجهود القدير ...
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
671
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
20
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Multimedia lecture ActionScript3

  1. 1. Eng: Mohammed Hussein1Lecturer, and Researcher atThamar UniversityBy Eng: Mohammed Husseinmohammedhbi@thuniv.net
  2. 2. Output and trace in ActionScript 3.0Eng: Mohammed Hussein2 Define a variable and print it. Define for loop. Define a function to objectduring an event.
  3. 3. Arrays In ActionScript 3.0Eng: Mohammed Hussein3 For example :
  4. 4. Using Mouse Events to Control PropertiesEng: Mohammed Hussein4 Events are responsible for setting your scripts in motion, causingthem to execute. A button can be triggered by a mouse event, text fields react tokeyboard events—even calling your own custom functions. InActionScript 3.0, trapping events is simplified by relying on oneapproach for all event handling, which is to use event listenersregardless of the type of event or how it is used.
  5. 5. EventsEng: 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. 6. Event HandlingEng: Mohammed Hussein6 Event handling is the process by which any sort of interactivity iscreated in ActionScript 3.0. Event Handling system of AS3 are reacting to a mouse click, akeyboard stroke, or any event happening in Flash which is divided intothe following sections:1. Basic Event Handling Using the .addEventListener() method.2. Unregistered Events Listeners usingthe removeEventListener() method.3. Working with EventTargets.
  7. 7. Event ListenerEng: Mohammed Hussein7 AnActionScript Event is any interaction happening in the Flashenvironment, whether it was a mouse click, the movement of thetimeline to a new frame, the completion of the loading process of anexternal asset, or any other occurrence. ActionScript can make any object react to any event by using an EventListener. An event listener is basically a function created with the very specific purposeof reacting to an event. An object can react to an event using an event listener.This is done by usingthe .addEventListenermethod.This method simply registers an EventListener and an Event to an object. The process described above is written in ActionScript using in theformat shown below:myObject.addEventListener(Event, eventListenerFunction);
  8. 8. addEventListener() methodEng: Mohammed Hussein8Our Event Listener will obviously have to be specified by declaringthe function the same way any other function is declared inActionScript, the only difference is that the listener function musthave one argument to represent the event.This event argument can have any identifier as its name, usually usedthe 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. 9. Event can be registeredEng: Mohammed Hussein9 for example, if we want a graphical object placed on stage to act like abutton by reacting to a mouse click over it, we can simply register an eventand an event listener to it this way: For example, if you are using the Loader Class to load an external asset atrun time, you can perform a specific action only when the asset you aretrying to load finishes loading. For this, you will need to register for theEvent.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. 10. Unregistering Event ListenersEng: Mohammed Hussein10 To unregister an event you can use the .removeEventListener() method inthe same exact way the .addEventListener() method is used.This methodrequires specifying the object from which the event listener is to beunregistered, the event to stop listening to, and the function that wasassigned to this specific event. Here is a generalized code on the usage ofthis method:myObject.removeEventListener(Event, eventListenerFunction);For example, if an event listener function was registered to be triggered onthe entry of each new frame on the main timeline we would have registeredit this way:this.removeEventListener(Event.ENTER_FRAME, loading);
  11. 11. Event Targets and Event PropagationEng: Mohammed Hussein11 Depending on the event handled, an event would usually occur to a specificobject. For example, a click event will happen to a specific button and a loadcomplete event will happen to a specific instance of the loader class.1. EventTarget with name movie, if we want an object to become hidden whenclicked, within the listener function to hide it this way:2. EventTarget without specifying its name complex movies , we use thekeyword e.currentTarget because you want to reuse the same listener functionwith more than one object. Now reuse this listener function for more than oneobject without fear of breaking the code because of the smart reference to ourevent 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. 12. Adding childrenEng: Mohammed Hussein12 It is possible to refer to the children of an object to which an eventwas registered using the keyword e.target (as opposed toe.currentTarget) to refer directly to these objects. For example, if we have a MovieClip movie that has three buttons, we canhide each of these buttons on its own when individually clicked byregistering ONE event listener to ONE object only, which is in this casethe 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_mchas three buttons, we can hideeach of these buttons on itsown when individuallyclicked.The event listener functionregistered with the actualbutton clicked to e.target
  13. 13. Sound effects13 Eng: Mohammed Hussein
  14. 14. Sound effect example14 Eng: Mohammed Hussein
  15. 15. Playing sounds using ActionScript 3.0Eng: Mohammed Hussein15 Playing sounds using ActionScript 3.0 is not as simple as we hopedit to be as it requires using more than one class to perform even thesimplest of tasks relating to sound such as pausing or changing thesound volume. Introduction to Sound Related Classes. Playing an Internal Sound. Playing an External Sound. Stopping a Sound. Pausing a Sound. Changing SoundVolume.
  16. 16. Sound classes Sounds in ActionScript 3.0 are manipulated through the collaborative work of severalclasses together.This format will provide you with greater control and the ability to micromanage 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 isthe 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 whichprovides additional controls over a sound object, the most basic of these additionalcontrols is the ability to stop the playback of a sound.3. SoundTransform Class -This class is responsible for altering sound volume andsound panning (manipulating the balance between the left and right speakers).4. SoundMixer Class -This class has global control over all sounds played in the Flashplayer. Its most basic function is to stop all playing sounds regardless of source.16 Eng: Mohammed Hussein
  17. 17. Load soundEng: Mohammed Hussein17 Two ways to load sound into flash:1. First by using this code of AS32. Second one using import sound intoflash
  18. 18. Stop soundEng: Mohammed Hussein18 To stop all sounds in your movie use this code:
  19. 19. Animated SpeakersEng: Mohammed Hussein19 Sound example
  20. 20. Animated Speakers and Equalizer Trick(ASET) projectEng: Mohammed Hussein20 .stop() - this method stops the soundplaying through the channel. .position - this property is used toretrieve the current playback position of the sound playingthrough the channel. .soundTransform - this property is usedto set and retrieve soundtransformations such as volumeand panning.
  21. 21. (ASET) project stepsEng: Mohammed Hussein211. Set Boolean value for buttons Play and Stop functions.2. Create the sound object3. Create the URL request that grabs the MP3 to play from your server orhard drive.4. Load the URL request into the Sound object5. Create the SoundChannel variable.6. Start playing the sound here in the channel variable7. 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. 22. (ASET) project codeEng: Mohammed Hussein22 onEnterFramefunction run in loopwhich can manipulateour idea. onPlaybackCompletefunction, used whenthe song finishes tostop channel playing.
  23. 23. Playing Video example23 Eng: Mohammed HusseinTo add video into the Display List usethe addChild() method.The .source property is used to specify the video to be played.
  24. 24. Applying a Skin to FLVPlayback ComponentEng: Mohammed Hussein24 The FLVPlayback Component is used when you want to play a video. To import the component to Library will require us to access theComponents Panel by going throughWindow>Component , look for theFLVPlayback Component under theVideo category and then drag and dropan instance of it on stage and then delete it.Which should store an instanceof the component in the Library. The graphical elements of skin are actually saved in a separate SWF file thatis loaded at run time by the main SWF movie. If you have the skin SWF fileavailable you simply set its URL as the value for a property called . Select your component on the stage and properties then skin.
  25. 25. Slide showEng: Mohammed Hussein25 Give a title namefor thisActionScript3 code?
  26. 26. ColorEng: Mohammed Hussein26 Give a title namefor thisActionScript3code? AS3 ChangingColors
  27. 27. What is the output of this code?Eng: Mohammed Hussein27Output:Venus,Earth,Mars
  28. 28. What is the output of this code?Eng: Mohammed Hussein28Output :Maybe #0: IMaybe #1: amMaybe #2: HereMaybe #3: OkMaybe # 3: Ok 4Maybe # 3: Ok 4
  29. 29. What is the output of this code?Eng: Mohammed Hussein29Output :80
  30. 30. What is the output of this code?Eng: Mohammed Hussein30Output :10 1511 1611 16
  31. 31. After you Clicked the button and write theoutputs ?Eng: Mohammed Hussein31Output :mohammedalisalim
  32. 32. What is the output of this code?Eng: Mohammed Hussein32Output :-1true
  33. 33. What is the output of this code?Eng: Mohammed Hussein33Output :y: 33x: 24
  34. 34. Correct the flowing code and write theoutput ?Eng: Mohammed Hussein34
  35. 35. What is the output of this code?Eng: Mohammed Hussein35Output :Hello, Dr. Mohammed, nice to meet you.Hello, saddam, nice to meet you.

×