1 / 25

Loading External content

Loading External content . Text, Images, Sound, Video and SWFs. Load other file using URLRequest URLLoader URLVariables. Flash / Actionscript. Loading E xternal F iles. To load an external (SWF/text/sound/image) file, your ActionScript needs to do 4 things :

yestin
Download Presentation

Loading External content

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Loading External content Text, Images, Sound, Video and SWFs

  2. Load other file using URLRequest URLLoader URLVariables Flash /Actionscript

  3. Loading ExternalFiles • To load an external (SWF/text/sound/image) file, your ActionScript needs to do 4 things: • Create a new URLRequest object with the url of the file. • Create a new Loader object. • Call the Loader object's load() method, passing the URLRequest instance as a parameter. • Call the addChild() method on a display object container (such as the main timeline of a Flash document) to add the Loader instance to the display list.

  4. varvariables:URLVariables = new URLVariables(); varrequest:URLRequest = new URLRequest(); request.url = "image.jpeg"; varloader:URLLoader = new URLLoader(); loader.load(request); Set up Flash objects

  5. Loading Data from External Sources: • varrequest:URLRequest = new URLRequest("params.txt"); • varloader:URLLoader = new URLLoader(); • loader.load(request); • or • varloader:URLLoader = new URLLoader(new URLRequest("params.txt"));

  6. Loading External SWF: • It is easier to have the external .swf(s) in the same folder as the .swf loading it. You can put in a longer path, but placing it in the same folder cuts down on potential path errors. • When you want to load the .swf, add a key frame and the following code to actions layer: • varswfRequest:URLRequest = new URLRequest("connect.swf"); • varswfLoader:Loader = new Loader(); • The first line sets up a variable called swfRequest that is an instance of the URLRequest object that will points to the .swf you want to load. In this example, the .swf is called "connect.swf". • The second line sets a variable called swfLoaderto initiate as an instance of the loader object. • The next line loads the connect.swf into the variable swfLoader. • swfLoader.load(swfRequest); • The addChild method places the loader with the .swf onto the stage. • addChild(swfLoader);

  7. Loading External SWF: • To place the .swf in a particular location on the stage, you can manipulate it's x and y coordinates once its been loaded into your main .swf. • swfLoader.x=10; • swfLoader.y=120; • This sets the X and Y placement of the .swf after its been loaded. • Remember, that the X and Y coordinates are relative to the main timeline (if this is where you loaded the movieclip) or relative to the coordinates INSIDE a movie symbol (if you drop loaded the movieclipinto a movieclip on the stage.)

  8. The complete code (with comments added): • // Load the SWF into the Variable swfRequest • varswfRequest:URLRequest = new URLRequest("connect.swf"); • varswfLoader:Loader = new Loader(); • // Bring the SWF into the Stage or current SWF • swfLoader.load(swfRequest); • addChild(swfLoader); //this.addChild(swfLoader); • //Position the SWF • swfLoader.x=10; • swfLoader.y=120;

  9. Dynamically Load an External Image • To load an image (or swf) dynamically from a folder on the server requires a little more work but is essentially the same process as loading a movie clip from your library. • First you will define a URLRequest variable to hold the location of the file you want to load into the program. • varimage01:URLRequest = new URLRequest("enter URL here"); • Second you will need to create a Loader object. • varmyLoader:Loader= new Loader(); • In this case the loader object is named myLoader and it is instantiated with the new keyword. • Third, the add child command is used to add the loader to the stage. • this.addChild(myLoader); • Fourth, you have to display the image in the loader you previously created using the load method of the Loader class. • myLoader.load(image01); • In the preceding example, the load method of the myLoader object loads the URLRequestinto the object named myLoader.

  10. Loading External Content Sound and video

  11. Sound/Audio • Two ways for including audio: • Associate the sound with a frame Or • Use Actionscript code • to get the sound file • to set a Sound object • to start and stop and …

  12. Internal and External Sound • In Flash there are basically two different ways of working with sound - Internal(sound in library) and External Sound(loading a sound) • It is recommended to use external sounds - by loading a sound into the application, you can keep the total file size down • Examples of how to use the different types: • External sound: Load a sound file (MP3) into the application. This could be for example: background music, mp3 player etc. • Internal sound: Attach sound from Library (linkage). Use small sounds (in file size), for example sound effects for a game, button click-sounds etc.

  13. Working with Sound Files • Importing a sound demo – Internal Sound file in Library • Download sound file • Within flash click File>Import>Import to Library • Select sound file in Library • Double click on imported sound to adjust settings • Under Compression change to MP3 (will make file size much smaller) • Modify Bit rate to 24kbps • Leave Preprocessing(convert stereo to mono) unchecked • For Quality select Best

  14. Working with Sound Files • Importing a sounddemo – Internal Sound file in Library • Click Test to preview sound • OK to accept settings • Create a new layer and name it soundtrack • Click on the first frame of this layer, drag sound from library onto stage • Within the Properties inspector verify that Sync is set to Event for this sound clip • (Event for sync will begin to play sound when play head reaches the frame where the sound is, frame 1 of soundtrack layer, and the playing of the sound is independent of the main timeline) • Modify sound clip effects if you like • Control>Test Movie

  15. Loading External Sound using AS3 • Create new Fla file in same folder as sound file (.mp3), make sure you have an actions layer. • Click in Frame 1 of your actions layer and open the Actions Panel (if it is not already open). • To import a sound file we begin with a "URLRequest" that tells Flash where the file is located. On the first line of the Actions panel type: • varmySoundReq:URLRequest = new URLRequest("songsample.mp3");

  16. Loading An External Sound File • create a new instance of the Sound class • type: varmySound:Sound = new Sound(); • use the created Sound object to load the MP3 file • type: mySound.load(mySoundReq);

  17. Loading External Sound using AS3 • To make sure the MP3 file begins to play once the sound has finished loading, add an event listener and an event handler • The event listener will "listen" to the mySound object we created and when it has finished loading the sound it will trigger the function. • The event handler will actually play the MP3 file. • Type: • mySound.addEventListener(Event.COMPLETE, playSong);

  18. Loading External Sound using AS3 • the playSong event handler: • function playSong(event:Event):void {mySound.play();} • Save your movie and press command-return (or control-enter) to test it. Your MP3 file should begin to play immediately. • Be aware that when you place your Flash movie online using this method the MP3 file will NOT begin to play immediately – specifically the entire MP3 file will load THEN the MP3 file will play. • Depending upon the size of your MP3 file there will probably be a short pause as the entire file loads.

  19. Loading External Sound using AS3 varmySoundReq:URLRequest = new URLRequest("songsample.mp3"); varmySound:Sound = new Sound(); mySound.load(mySoundReq); mySound.addEventListener(Event.COMPLETE, playSong); function playSong(event:Event):void {mySound.play();}

  20. Sources for Sound • http://www.freesound.org/ • http://mp3.about.com/od/freebies/tp/freemusictp.htm • http://www.findsounds.com/

  21. Multiple ways to incorporate video into Flash We will use the FLVPlaybackobject, manually placed onto the stage Different types of videos (like different types of images) Flash video playback requires videos of type .flv Can use Adobe Flash Media Encoder (part of the Adobe CS5 package) to convert different types of video to flv Video in Flash:FLV Playback

  22. The Skins are the video clip controls. There are several skins of different designs available Skins are appropriate when you want to give the player/user/customer more controls You may choose NOT to give user control in certain cases Requires you to upload an .swf file to the server. This swf file will have the name of the skin you chose for the flv player. If you do not upload your skin the flv player will be missing its controls for play, stop, volume etc. Video in Flash: FLV Playback Skins

  23. Video in Flash:File Organization • Your folder could consist of the following files. Say your application is called mywork.fla • mywork.html • mywork.swf • For each video: f1.flv, f2.flv, etc. The names f1, f2, need to be replaced by the names you gave the video. (Remember: no blanks!) • For each skin: the name of the skin file: xxxx.swf

  24. Flash CS5: FLV Playback (Video Tutorial) • http://www.webdesign.org/flash-swish/flash-tutorials/flash-cs5-flv-playback-video-tutorial.18633.html • For more information: • Adobe Flash Professional CS5 & CS5.5 * Add video to Flash • http://help.adobe.com/en_US/flash/cs/using/WSb03e830bd6f770ee-70a39d612436d472f4-7ff8.html

  25. Examples to Study • loadingtext • loadingtext_dynamic • loadImages • loadImages_multiple • LoadingInternalSound • loadingsound • loadingExternalSWF • loadingExternalSWFmultiple • flvplay • Load External Images into Flash CS5 • Load External Text into Flash CS5 • loadingexternal-1

More Related