180 likes | 306 Views
Programming Behavioral Experiments in Flash Advanced Topics if Flash (Sounds, Videos, and Real Time Ratings). July 23 rd and 24 th , 2009– Jeff Galak (CMU). Agenda for Today. How to play sounds How to collect real time ratings How to play videos How to convert videos to Flash format
E N D
Programming Behavioral Experiments in FlashAdvanced Topics if Flash (Sounds, Videos, and Real Time Ratings) July 23rd and 24th, 2009– Jeff Galak (CMU)
Agenda for Today • How to play sounds • How to collect real time ratings • How to play videos • How to convert videos to Flash format • How to “rip” videos from YouTube Flash Workshop - Intro to Web Programming, PhP, and Flash
Working with Sound Files • Import sound file to library • File->Import->Import to Library • Within the library, create a “linkage” • Right click on sound file -> Linkage • Check “Export for Actionscipt” • Give your file a name • Ok • Now your file is ready to be accessed via ActionScript Flash Workshop - Intro to Web Programming, PhP, and Flash
Sound File + Actionscript • Define a “sound variable” • var currentsound:Sound = new Sound (); • Created a variable called “currentsound” • Attach a sound file to the new variable • currentsound.attachSound("sample"); • Attached the sound file “sample” to “currentsound” • Play the file • currentsound.start(0,1); • Plays the sound file associated with “currentsound” • The first argument “0” tells it to start at the begninning of the song • The second argument “1” tells is the number of times to play the sound (once, in this case) Flash Workshop - Intro to Web Programming, PhP, and Flash
Other Things to Remember with Sound Files • You can stop your sound file with the stop() command: • currentsound.stop(); • You can change the volume with the volume command (0 to 100): • currentsound.setVolume(50); • You can have the program do something (e.g. go to the next frame) when the sound is done playing: currentsound.onSoundComplete = function() { nextFrame(); } Flash Workshop - Intro to Web Programming, PhP, and Flash
Collecting In-Experience (Online) Ratings • Two ways to do this: • Stop people every X seconds and collect a measure • Have a slider-scale that continuously records a value • We will focus on the latter. Flash Workshop - Intro to Web Programming, PhP, and Flash
Online Scale Set up (With a Song) Scale Flash Workshop - Intro to Web Programming, PhP, and Flash
Online Scale Code Code for song Code for slider scale Tells flash to run the function “collectdata” every 3 seconds When this function is run, it simply stores the value of the scale Flash Workshop - Intro to Web Programming, PhP, and Flash
Things to Remember with Online Scales • You can change the frequency of the data collection by changing the number in the myTimer line. Time is in milliseconds. • Make sure to add the clearInterval command when you leave the frame • In this case, when the sound stops playing Flash Workshop - Intro to Web Programming, PhP, and Flash
Working with Videos • Videos need to be in .flv (flash video) format. • You can convert them using flash. • File -> Import -> Import Video • This takes a long time but works well. • You can use 3rd party software for conversion • Allok Video to FLV Converter • http://www.alloksoft.com/flv_converter.htm • Works much faster, but sometimes the converted file doesn’t work. No clue why. Flash Workshop - Intro to Web Programming, PhP, and Flash
Ripping Video from YouTube • http://www.savevid.com/ • Simply copy+paste the URL from youtube into the box on savevid.com • Make sure the file extension is .flv • Done. Flash Workshop - Intro to Web Programming, PhP, and Flash
Editing FLV Files • Adobe Air + RichFLV • Adobe Air: http://www.adobe.com/products/air/ • RichFLV: http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1355018 • Install Air first. • RichFLV lets you edit FLV files quickly. Flash Workshop - Intro to Web Programming, PhP, and Flash
Flash and Videos • Create a video placeholder with the “my_video” object in the library. • Name it something: my_video • Make sure that the video file is somewhere on the web (even while testing). Flash Workshop - Intro to Web Programming, PhP, and Flash
Actionscript and Videos This is the only line you really care about This block of code is optional. It allows you to skip the video by hitting CTRL+A Flash Workshop - Intro to Web Programming, PhP, and Flash
What About Online Measures and Videos? Just add the scale and the myTimer code: myTimer = setInterval(collectdata,3000); iteration=1; function collectdata() //function that stores the data { ratio=Math.round(((Slider.dragger._x-(Slider.dragger._width/2))/(Slider.line._width))*sliderMaximum); storedata("soundrating_"+iteration,ratio); iteration++; } Flash Workshop - Intro to Web Programming, PhP, and Flash
Dynamic Feedback • Text is easy (we saw this in the first program) • Graphs and figure are more difficult • Basic bar chart implementation… • Place a “barchart” object on the stage. • Double click on it • Click on the only frame to open the actionscript Flash Workshop - Intro to Web Programming, PhP, and Flash
Dynamic Feedback – Bar Chart chart_values = [20,-7, 3, 5]; chart_group_names = ["Test 1", "Test 2", "Test 3", "Test 4”]; chart_height = 300; chart_width = 500; chart_data_values = true; chart_x_axis_lables = true; chart_x_axis_name = "Groups"; chart_y_axis_name = "Values"; Flash Workshop - Intro to Web Programming, PhP, and Flash
That’s It! • Go forth and collect data! • Spread the gospel of Flash. • And most importantly, have a great weekend. Flash Workshop - Intro to Web Programming, PhP, and Flash