80 likes | 204 Views
Introduction to. Flash ActionScript. Sound, Video & XML (image gallery). Thomas Lövgren thomas.lovgren@humlab.umu.se. Ex. Sound. loadSound(): Dynamic loading //create a sound object var bg_sound:Sound = new Sound(); bg_sound.loadSound("bgSound.mp3", true); //load, streaming = true
E N D
Introduction to Flash ActionScript Sound, Video & XML (image gallery) Thomas Lövgren thomas.lovgren@humlab.umu.se
Ex Sound • loadSound(): Dynamic loading //create a sound object var bg_sound:Sound = new Sound(); bg_sound.loadSound("bgSound.mp3", true); //load, streaming = true bg_sound.start(); trace(”backgroundsound on!"); //output //looping background sound bg_sound.onSoundComplete = function(){ bg_sound.start() } • attachSound(): Get sound from library effect_sound.attachSound("effect_sound"); //linking in library effect_sound.start(); trace(“sound effect on!"); //output
Video (1/2) • Flash Video (.flv): Dynamic loading • Streaming: ex. with Flash Media Server • Progressive downloading: Short clips (ex. YouTube) • Two methods: • 1) Video component with skin (automatic) • 2) Actionscriptbased video (more options) – loading through a video object • Flash Video can be created and modified by: • Sorenson Squeeze • Flash 8 / Flash CS3 (File/Import/Import Video ) • Check settings: size/resolution, framerate, encoding, sound etc.
Ex Video (2/2) • Actionscriptbased video • Create a video object: Right-click in Library and choose: ”New Video” click Video (Actionscript – controlled) • Drag the symbol and place it on stage, name it tomy_video //video object on stage var my_video:Video; //create a NetConnection object var my_nc = new NetConnection(); my_nc.connect(null); //open connection //netStream object for videostream var my_ns = new NetStream(my_nc); my_ns.setBufferTime(5); //buffer 5 sec, then play! my_ns.seek(0); //start at (time = 0) //add the stream object my_video.attachVideo(my_ns); //play current video clip my_ns.play("kickbackCD.flv");
XML • Similar function with a database (only read access) • Often used in combination with Flash • XML works like a tabel/list for holding data • Using XML for (Dynamic) loading of data (ex. Sound, images, video) • A technique for reducing the filesize of the application • Easy to update
The XML structure • The XML file imgData = this.firstChild.childNodes;
XML (1/2) • Build the ”XML structure” in a texteditor, ex: <?xml version="1.0" encoding="UTF-8"?> <images> <image info=”Maldiverna" path="gallery/image01.jpg"></image> </images> • Save as myFile.xml (encoding UTF-8)
Ex XML (2/2) • Load data intoFlashthrough a XML object var my_xml = new XML(); my_xml.ignoreWhite = true; my_xml.load("gallery/imageData.xml"); var image:Number = 0; my_xml.onLoad = function(status) { if (status) { imgData = this.firstChild.childNodes; loadMovie(imgData[image].attributes.path, "mc"); display_txt.text = imgData[image].attributes.info; image_txt.text = "Bild " + (image + Number(1)) + " / " + imgData.length; deletemy_xml; } else { display_txt.text = "Data cannot be loaded!"; } };