Solved

flash cs3 help setting up AS3 button to play video as well as audio

Posted on 2008-10-11
1
2,886 Views
Last Modified: 2013-11-11
I'm using AS3 with flash cs3. I've followed a tutorial to get my buttons to play an audio file. Is it possible to get these button to play, stop and pause my video file (movie symbol, instance name play.swf) along with the audio? Any help would be appreciated.

//----CODED BY CRAIG CAMPBELL AT SCHOOL OF FLASH--------//
//-------- http://www.schoolofflash.com----------//

var music:Sound = new Sound(new URLRequest("fhtwaudio.mp3"));
var sc:SoundChannel;
var isPlaying:Boolean = false;
var pos:Number = 0;
var soundVolume:Number = 1;
var muted:Boolean = false;

mute_mc.buttonMode = true;
volume_mc.slider_mc.buttonMode = true;

pause_btn.addEventListener(MouseEvent.CLICK, pauseMusic);

function pauseMusic(e:Event):void
{
      if (isPlaying)
      {
            pos = sc.position;
            sc.stop();
            isPlaying = false;
      }
}

stop_btn.addEventListener(MouseEvent.CLICK, stopMusic);

function stopMusic(e:Event):void
{
      if(sc != null)
      {
            sc.stop();
            pos = 0;
            isPlaying = false;
      }
}

play_btn.addEventListener(MouseEvent.CLICK, playMusic);

function playMusic(e:Event):void
{
      if (!isPlaying)
      {
            sc = music.play(pos);
            isPlaying = true;
      }
}


//---VOLUME SLIDER---//
var dragging:Boolean = false;
var rectangle:Rectangle = new Rectangle(0,0,100,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function dragIt(e:Event):void
{
      volume_mc.slider_mc.startDrag(false,rectangle);
      dragging = true;
      volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}

function dropIt(e:Event):void
{
      if (dragging)
      {
            volume_mc.slider_mc.stopDrag();
            volume_mc.slider_mc.removeEventListener(Event.ENTER_FRAME, adjustVolume);
            dragging = false;
      }
}

function adjustVolume(e:Event):void
{
      mute_mc.gotoAndPlay("On");
      soundVolume = volume_mc.slider_mc.x / 100;
      var st:SoundTransform = new SoundTransform(soundVolume);
      if (sc != null)
      {
            sc.soundTransform = st;
            muted = false;
      }
}

mute_mc.addEventListener(MouseEvent.CLICK, mute);

function mute(e:MouseEvent):void
{
      if (sc != null)
      {
            var st:SoundTransform;
            if (muted)
            {
                  st = new SoundTransform(soundVolume);
                  sc.soundTransform = st;
                  mute_mc.gotoAndStop("On");
                  muted = false;
            }
            else
            {
                  st = new SoundTransform(0);
                  sc.soundTransform = st;
                  mute_mc.gotoAndStop("Mute");
                  muted = true;
            }
      }
}
//----CODED BY CRAIG CAMPBELL AT SCHOOL OF FLASH--------//

//-------- http://www.schoolofflash.com----------//
 

var music:Sound = new Sound(new URLRequest("fhtwaudio.mp3"));

var sc:SoundChannel;

var isPlaying:Boolean = false;

var pos:Number = 0;

var soundVolume:Number = 1;

var muted:Boolean = false;
 

mute_mc.buttonMode = true;

volume_mc.slider_mc.buttonMode = true;
 

pause_btn.addEventListener(MouseEvent.CLICK, pauseMusic);
 

function pauseMusic(e:Event):void

{

	if (isPlaying)

	{

		pos = sc.position;

		sc.stop();

		isPlaying = false;

	}

}
 

stop_btn.addEventListener(MouseEvent.CLICK, stopMusic);
 

function stopMusic(e:Event):void

{

	if(sc != null)

	{

		sc.stop();

		pos = 0;

		isPlaying = false;

	}

}
 

play_btn.addEventListener(MouseEvent.CLICK, playMusic);
 

function playMusic(e:Event):void

{

	if (!isPlaying)

	{

		sc = music.play(pos);

		isPlaying = true;

	}

}
 
 

//---VOLUME SLIDER---//

var dragging:Boolean = false;

var rectangle:Rectangle = new Rectangle(0,0,100,0);

volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);

stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
 

function dragIt(e:Event):void

{

	volume_mc.slider_mc.startDrag(false,rectangle);

	dragging = true;

	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);

}
 

function dropIt(e:Event):void

{

	if (dragging)

	{

		volume_mc.slider_mc.stopDrag();

		volume_mc.slider_mc.removeEventListener(Event.ENTER_FRAME, adjustVolume);

		dragging = false;

	}

}
 

function adjustVolume(e:Event):void

{

	mute_mc.gotoAndPlay("On");

	soundVolume = volume_mc.slider_mc.x / 100;

	var st:SoundTransform = new SoundTransform(soundVolume);

	if (sc != null)

	{

		sc.soundTransform = st;

		muted = false;

	}

}
 

mute_mc.addEventListener(MouseEvent.CLICK, mute);
 

function mute(e:MouseEvent):void

{

	if (sc != null)

	{

		var st:SoundTransform;

		if (muted)

		{

			st = new SoundTransform(soundVolume);

			sc.soundTransform = st;

			mute_mc.gotoAndStop("On");

			muted = false;

		}

		else

		{

			st = new SoundTransform(0);

			sc.soundTransform = st;

			mute_mc.gotoAndStop("Mute");

			muted = true;

		}

	}

}

Open in new window

0
Comment
Question by:elliottbenzle
1 Comment
 
LVL 6

Accepted Solution

by:
gxp071 earned 250 total points
ID: 22701306
sure, you just need to target the video mc and tell it to do what you want,

i'm assuming your using netstream to play an external flv file.  Just add

_root.pathtovideo_mc.NetStreamObjectName.pause()

_root.video_mc.ns.pause();

To the button function call to toggle pause/play  .stop() to stop,

But you can add any function calls you like to the button as long as the target path is correct, and you remember the function is executed in the button, even if you attach the function from the first frame of the root movie clip.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
YouTube Link 10 354
Action Script commands 4 305
Array is not working ( AS2 ) 4 146
free flash maker 5 206
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now