Download presentation
Presentation is loading. Please wait.
Published byRodney Webb Modified over 8 years ago
1
Programming Games Reprise: radio buttons. Creating instances at runtime. Buttons. Present your sound or video. Final project assignment. Homework: [Catch up]. Post your proposal for final project.
2
Radio buttons Window / Components Radio buttons are organized in groups –YOU MUST specify the common groupName using the Properties panel –You can specify a value for each button ActionScript can check selected property of each button or the selection property of the group
3
Sample radio button code var rg:RadioButtonGroup = RadioButtonGroup.getGroup("choices"); rg.addEventListener(MouseEvent.CLICK,picked); function picked(ev) { var ch = rg.selection; var chnum = Number(ch.value); // do something with chnum }
4
video example Need to acquire / create flv source files Need to put FLVPlayback into Library. –Can do this by going to Windows/Component/ Video/ Move FLVPlayback to Stage and then erase. Need to find the skin and copy to folder of the.fla file Need to put radio buttons on the Stage: Windows/Components/Radiobutton and set groupName of each to choices and value of each to the name/type of an flv file.
5
video example import fl.video.*; import flash.events.Event; import fl.events.ComponentEvent; import fl.controls.RadioButtonGroup; var flv:FLVPlayback= new FLVPlayback(); var rg:RadioButtonGroup = RadioButtonGroup.getGroup("choices"); rg.addEventListener(MouseEvent.CLICK,whichbutton); function whichbutton(ev) { var whichb:RadioButton = rg.selection; var videoname:String = String(whichb.value); playvideo(videoname); }
6
video example, cont. function playvideo(vname) { flv.source = vname; flv.skin = "SkinUnderPlayStopSeekFullVol.swf"; flv.addEventListener(VideoEvent.COMPLETE,re moveflv); addChild(flv); } function removeflv(ev) { removeChild(flv); }
7
arrays… are very useful! Can use to create an indeterminate number of things. Can store information generated using Math.random. Use push to add elements. Use indexing [ ]. Parallel arrays / parallel structures useful for holding corresponding pieces of information.
8
Creating instances at runtime Suppose you want to create some number of instances of a Movie Clip symbol on the Stage, possibly at random positions. Create the Movie Clip symbol. Need to prepare it for ActionScript: –In Library list, select and then right-click –Properties –Advanced: set Export for ActionScript. Can accept default Class name, or make new one. Accept that class does not exist and new class is to be created.
10
sample code for creating trees… var numOfTrees = 3; var i; var trees = []; var best; function startup() { for (i=0;i<numOfTrees;i++) { var ntree = new Tree(); ntree.x = Math.random()*550; ntree.y = Math.random()*400; addChild(ntree); trees.push(ntree); }
13
Buttons Window / Common Library –May want to edit to change text field DIY (rock paper scissors) –Insert … New Symbol specify button –Create UP, OVER, DOWN & HIT frames Window / Components / User Interface / Button –Note: has label field to be changed All cases require naming the button instance on the Stage!!!!
14
slider example Uses one function to handle 3 distinct events (two sliders and one button) Use slider from Components Use parameter passed to handler to determine what instance had event.
15
slider code: set up event handling scrollw.addEventListener(SliderEvent.CHANGE,react); scrollh.addEventListener(SliderEvent.CHANGE,react); mybutton.addEventListener(MouseEvent.CLICK,react); var origwidth=mycircle.width; var origheight=mycircle.height;
16
function react(ev:Event) { switch (ev.target.name) { case "scrollw" : mycircle.width=origwidth*scrollw.value/100; break; case "scrollh" : mycircle.height=origheight*scrollh.value/100; break; case "mybutton" : if (mybutton.label=="Remove") { mycircle.visible=false; mybutton.label="Restore"; } else { mycircle.visible=true; mybutton.label="Remove"; }
17
Final project Your choice (don't be too ambitious) Modification of coding for any class project Your version of any other project on my page Anything you want!
18
Classwork / homework Show sound or video. Discuss final project. Make proposal on moodle. –Look for my response –You can make constructive suggestions to other postings.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.