1
Advanced Actionscript Advanced Actionscript for Flash 5for Flash 5
by Dr SC Liby Dr SC Li
2
Exercise 1Exercise 1(Creating sound objects)(Creating sound objects) Download and unzip the file sound1-ex.zip Open the library window by clicking
Windows > LibraryWindows > Library To establish a linkage for the sound symbol,
highlight “technoloop” and right click it and choose the “LinkageLinkage” option.
To create an action for Frame 1: Highlight Frame 1 Frame 1 and right click it, then choose “Actions”“Actions”
3
Exercise 1Exercise 1(Creating sound objects)(Creating sound objects) Select the “Expert ModeExpert Mode” for the script editor and
type in: function mysound(music){ soundobject=new Sound(this);
soundobject.attachSound(music); soundobject.start(0,50); soundobject.setVolume(100); } mysound("soundtrack")
4
Exercise 1Exercise 1(Creating sound objects)(Creating sound objects) To select buttons from the Common
Libraries, click Windows > Common Windows > Common Libraries > Buttons > (Oval) Button SetLibraries > Buttons > (Oval) Button Set
Drag the “Oval-stopOval-stop” and the “Oval-playOval-play” symbols on to the main stage
To create an action for the stop button: highlight and right-click it, then select “Actions”“Actions”.
On the script editor, type in: on (press){ _root.soundobject.stop("soundtrack"); }
5
Exercise 1Exercise 1(Creating sound objects)(Creating sound objects)
Save and preview the file.
6
Exercise 2 Exercise 2 (Creating simple controls for (Creating simple controls for sound object)sound object)
Download and unzip the file sound2-ex.zip To select buttons from the Common Libraries,
click Windows > Common Libraries > Windows > Common Libraries > Buttons > (Rectangle) Button SetButtons > (Rectangle) Button Set
Drag two “Grey-button PlayGrey-button Play” symbols (volume-up; volume-down) on to the main stage
To create actions for the buttons: highlight and right-click it, then select “Actions”“Actions”.
7
Exercise 2 Exercise 2 (Creating simple controls for (Creating simple controls for sound object)sound object)
For the volume-up button, type in: on (press){ dummy=_root.soundobject.getVolume; _root.soundobject.getTransform(); mySoundTransformObject.ll= mySoundTransformObject.ll+10; mySoundTransformObject.rr= mySoundTransformObject.rr+ 10;
8
Exercise 2 Exercise 2 (Creating simple controls for (Creating simple controls for sound object)sound object)
if(mySoundTransformObject.ll <= 100 && mySoundTransformObject.rr <= 100){
_root.soundobject.setTransform( mySoundTransformObject); } }
9
Exercise 2 Exercise 2 (Creating simple controls for (Creating simple controls for sound object)sound object)
For the volume-down button, type in: on (press){ dummy=_root.soundobject.getVolume; _root.soundobject.getTransform(); mySoundTransformObject.ll= mySoundTransformObject.ll-10; mySoundTransformObject.rr= mySoundTransformObject.rr- 10;
10
Exercise 2 Exercise 2 (Creating simple controls for (Creating simple controls for sound object)sound object)
if(mySoundTransformObject.ll >= 0 && mySoundTransformObject.rr >= 0){
_root.soundobject.setTransform( mySoundTransformObject); } }
Then save and preview the file
11
Exercise 3Exercise 3(Creating sound preloader)(Creating sound preloader)
Download and unzip the file sound3-ex.zip Create a pre-loading animation while the
sound movie clip is being downloaded. Open the “attachsound.fla”“attachsound.fla” file and insert a
key fame for Frame 1. Drag the preloading symbol onto the stage
and name the instance as “preloaderpreloader”. Insert an action for the preloaderpreloader instance:
12
Exercise 3Exercise 3(Creating sound preloader)(Creating sound preloader)
onClipEvent(load){ loadMovieNum("soundsource3.swf",1) } onClipEvent(enterFrame){ percentloaded=Math.floor( (_level1.getBytesLoaded()/ _level1.getBytesTotal())*100); percentdisplay=percentloaded + "%”;
13
Exercise 3Exercise 3(Creating sound preloader)(Creating sound preloader)
if(percentloaded == 100 && !initialize){
_level1.mysound("soundtrack") initialize=true; _visible=false; } }
Save and preview the file
14
Exercise 4Exercise 4(Creating smart MC movie clip)(Creating smart MC movie clip)
Download and unzip the file smart-mc-ex.zip Open the file “smart-mc.fla” “smart-mc.fla” and create a
smart MC flash movie clip as shown in http://ited.hkubu.edu.hk/hkbu-ited/session5/actions/smart-mc/smart-mc.swf
15
Exercise 5Exercise 5(Creating simple scrolling text)(Creating simple scrolling text)
Download and unzip the file scrolltext1-ex.zip Open the file “scrolltext1.fla” “scrolltext1.fla” and create a
movie clip with scrolling text as shown in http://ited.hkubu.edu.hk/hkbu-ited/session5/actions/scrolltext1/scrolltext1.swf
16
Exercise 6Exercise 6(Creating auto scrolling text 1)(Creating auto scrolling text 1)
Download and unzip the file scrolltext2-ex.zip Open the file “scrolltext2.fla” “scrolltext2.fla” and create a
movie clip with auto-scrolling text as shown in http://ited.hkubu.edu.hk/hkbu-ited/session5/actions/scrolltext2/scrolltext2.swf
17
Exercise 7Exercise 7(Creating auto scrolling text 2)(Creating auto scrolling text 2)
Download and unzip the file scrolltext2-ex.zip Open the file “scrolltext3.fla” “scrolltext3.fla” and create a
movie clip with auto-scrolling text as shown in http://ited.hkubu.edu.hk/hkbu-ited/session5/actions/scrolltext2/scrolltext3.swf