Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Audio

Categories Flash Sound for Dynamic Sites
Author: Gonzalo Alustiza

 
Page 12
«prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 next»

This is the code for the function.

function sound (netscape_event,play){
var browser = initialCheck();
var soundTag = '';
The variable 'browser' is an array that holds values returned by the function initialCheck().

The function initialCheck detects browsers and languages. I will provide it in a 'clipped' version in the downloadable source code.

The only thing that matters here is that browser[1] holds 'IE' if it is Internet Explorer,'NE' if it is Netscape and 'NN' if other.

Use your favorite function to detect the browser. The important thing is that the code should be branched for IE or NE.

The var 'soundTag' will hold the text that references the name of the Movie Clip

var reg = /\W/;

The var 'reg' stores a Regular Expression. This regular expression will help parse the URL of the HTML element that called the function.

Remember that the syntax of /\W/ means a range of any non-alphanumerical character with the exception of the underscore.

if (browser[1]=='NE')soundTag = netscape_event.target.toString();

if (browser[1]=='IE'&&window.event.srcElement.getAttribute('pathname')!=null){
soundTag = window.event.srcElement.getAttribute('pathname');
}
else if(browser[1]=='IE'){
soundTag = window.event.srcElement.parentElement.getAttribute('pathname');
}

soundTag=soundTag.split(reg);

Here we get to our first branch. Depending on which browser is being used we will retrieve the HREF attribute of the <A> or <IMG> tag that fired this function in different ways.

In case of Netscape we will use the TARGET property of the EVENT object to achieve this.

If it is Internet Explorer we will use the EVENT object too, but due to events 'bubbling up', the syntax is a bit more complex.

We use the split function (from the string object) plus the Regular Expression to parse the URL and split it every time we find a non-alphanumeric character. Here's an example:

original URL: www.mysite.com/web/mypage.htm after splitting the string we get an array that looks like 0=www 1=mysite 2=com 3=web 4=mypage 5=htm The length for this array is 6 so, we will use array.length-2 so we get at array[4] which equals 'mypage'. This array element is the tag that has the same value as the name of one of the Movie Clips inside the Flash Movie

if (arguments[1]=='true'){
if(browser[1]=='NE'&&top.soundtown.document.embeds.misonido.PercentLoaded()!=0){
top.soundtown.document.embeds.misonido.TPlay(soundTag[soundTag.length-2])
}
if (browser[1]=='IE'&&parent.soundtown.document.misonido.PercentLoaded()!=0){
parent.frames['soundtown'].document.misonido.TPlay(soundTag[soundTag.length-2]);
}

}

If the array arguments[1] (the arguments of the function) equals 'true' it means that the sound should play.

Notice that we are checking the browser and whether the Flash Movie loaded at least 1%. This is a good place to insert error handling code since these checks are useless if the invisible frame cannot load its page. Also notice that to access the Flash Embed you have to use the EMBEDS array in Netscape or the name of the embed in IE.

PercentLoaded () is a method of the Flash Player that returns a number indicating the percentage of the movie that has been downloaded so far. If the movie loaded at least 1% it means that no problems arose while embedding the movie. This does not mean that the movie is ready to play, so you could check if the movie is 100% loaded before trying to play it.

TPlay (target as String) is a method of the Flash Player that lets you play a Movie Clip by passing the method a string with the name of the target (Movie Clip). See how the method gets its target name from the URL already parsed.

if (arguments[1]!='true'){ if (browser[1]=='NE'&& top.soundtown.document.embeds.misonido.PercentLoaded()!=0){ top.soundtown.document.embeds.misonido.TStopPlay(etiqueta[etiqueta.length-2]); top.soundtown.document.embeds.misonido.TGotoFrame(etiqueta[etiqueta.length-2],1);

}

if (browser[1]=='IE'&&parent.soundtown.document.misonido.PercentLoaded()!=0){ parent.frames['soundtown'].document.misonido.TStopPlay(etiqueta[etiqueta.length-2]); parent.frames['soundtown'].document.misonido.TGotoFrame(etiqueta[etiqueta.length-2],1);

} }

return; }

You can call the function using the play flag as an empty string and be sure that it will be assumed by the function to be a Stop order.

The TStopPlay(target as String) method instructs the player to stop playing a Movie Clip, accepting a string as the Movie Clip name.

After stopping the player we go to Frame #1 using the TGotoFrame (target as String, frame as Integer) method which accepts a string as a Movie Clip name and an integer as a frame number. The TGotoFrame method makes sure that every time we play the Movie Clip it will start from the beginning.

As you can see the code is pretty straightforward. In the next section we will see how to call this function from HTML using event handlers.

«prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 next»

» Level Intermediate

Added: : 2001-02-20
Rating: 6.34 Votes: 29
Hits: 4685
» Author
My name is Gonzalo Alustiza and I work as a chief developer at Soundtown Argentina. Soundtown is a ten year old music production company specializing in music for advertising and TV which started to develop sonification solutions for the Internet.
» Download
Download the files used in this tutorial.
Download (89 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments