Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! Link to Us Newsletter Tell a Friend

      Add Tutorial |

 

Advertise here

Create Speaking Characters for your website and Flash movies. 15 Day Free Trial




PHP Scripts

 

 Home > Tutorials  > ActionScript

Using FlashVars to pass Cue points

Author: djodin | Email
Website : www.djodin.com


Advertisement

In this tutorial I will use FlashVars to pass an array containing cue points to a MediaPlayback component into flash.

In this tutorial I am going to use it to stream mp3 files.
You can of course use it with flv files too.

First, create a new flash document (550x400), open the components window and drag a MediaPlayback component and a button to the stage.
Label the button "Cue" or what ever you want, and give it a instance name of "btn1".

Now, give the MediaPlayback component a instance name of "player", and go to its parameters and set contentPath to a mp3 file
(ex. http://www.example.com/my_audio.mp3).
Also set mediaType to MP3, and controlPolicy to On.


Let is select the first frame in timeline and open the actions panel.

First add:

stop();

var cue:Array = cuepoints.split(",");
current = 0;


Explanation:

stop();

Stop the movie.

var cue:Array = cuepoints.split(",");

Create a new array of the variable cuepoints.
The split function splits the variable at every comma.
This because our variable will look something like this:
"10,40,50,200,420".
The variable cuepoints is passed trough FlashVar, I will get back to this later.


Add this code under the previous one:

_root.btn1.onRelease = function() {
_root.player.play(cue[current]);
current++;
if (current>=cue.length) {
current = 0;
}
};

Explanation:

_root.btn1.onRelease = function() {

This line checks if the button is pressed (or here, released).

_root.player.play(cue[current]);

Tell the player to play from the next cue point in our "cue" array.

current++;

Increase the current variable with 1.
So when we press the button again, it will play from the next cuepoint in our array.

if (current>=cue.length) {
current = 0;
}

If the current cue point is greater or equal to the number of total cue points, set the first cue point as next.

};

Close the onRelease function.

Full code:

stop();

var cue:Array = cuepoints.split(",");
current = 0;


_root.btn1.onRelease = function() {
_root.player.play(cue[current]);
current++;
if (current>=cue.length) {
current = 0;
}
};

Download Source File

| 1 | 2 | !IE] | | IE] | | |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

5 users online