Link to home
Start Free TrialLog in
Avatar of Lico_w
Lico_w

asked on

Flash CS4 - Actionscript - Media Controller

I need more information on the flash cs4 media controller, such as how to make the seek and volume buttons work. Currently when I run the file the mp3 file plays and stops from the media controller but the volume and seek buttons do nothing.

I am new to actionscript so please don't over complicate it. Code below:

Timeline Code:
display.backgroundStyle = "none";
display.autoPlay = true;
display.playheadChange=paused;

var isPlaying:String = "notPlaying";
var kirupaSound:Sound = new Sound();
kirupaSound.attachSound("sample.mp3");

Controller Code
on (click)
{
      if (isPlaying <> null)
      {
            _root.kirupaSound.start(0, 99);      
            isPlaying = null;
            
      }
      else
      {
            _root.kirupaSound.stop();
            isPlaying = "notPlaying";
      }
}
on (volume)
{
      kirupaSound.volume = 1;
}
Avatar of blue-genie
blue-genie
Flag of South Africa image

here's a better tutorial on how to use the controller

http://www.flashconf.com/how-to/how-to-create-a-music-player-with-actionscript/

its not overcomplicated, step by step.
if you don't want to loop different songs, just put 1 song in the xml (that will be less complicated then explaining to you how to change th code to not load the xml)

Avatar of Flappi282
Flappi282

Try this:
Make two buttons on the stage with the names: toggleplay_btn.
Add a "stepper" named vol_mc. Set the maximum attribute to 100
Then add this code to the timeline
Timeline Code:

System.security.allowDomain("*");
var url = "http://www.example.com/path/to.mp3";
_root.mp3Player = new Sound(_root);
_root.mp3Player.attachSound(url);
var paused = false;
var soundPosition;
toggleplay_btn.onRelease = function() {
if(!paused){
soundPosition= _root.mp3Player.postion/1000;
_root.mp3Player.stop();
paused=true;
}else{
_root.mp3Player.start(soundPosition,true);
paused=false;
}
}
onEnterFrame = function(){
_root.mp3Player.volume = vol_mc.value;
}

Hope this helps
I wouldn't recommend using an onEnterFrame to check the status of the volume slider.
I went through  that tutorial that I posted step by step and it works.
Avatar of Lico_w

ASKER

Thanks to you both for your posts.

Blue Genie - I tried the tutorial you suggested and I can't get it to work, I get to step 9 and when I do an output the screen is blank with no component. Also I would prefer not to use an XML file if poss.

Flappi - I would much prefer to use the Media Controller component as it looks much smarter. I did however try your post and couldn't get it to work.
Avatar of Lico_w

ASKER

Okay making slight progress I now have a function on the timeline to adjust the volume. When a\ user selects the volume it's adjusted to a lower level. I now need a listener to capture what the value of volume selected by the user to pass to my function. Code below:

Timeline Code:
display.backgroundStyle = "none";
display.autoPlay = true;
display.playheadChange=paused;

var isPlaying:String = "notPlaying";
var kirupaSound:Sound = new Sound();
kirupaSound.attachSound("sample.mp3");

function setMyVolume(cValue)
{
      kirupaSound.setVolume(cValue);
}

Controller Code:

on (click)
{
      if (isPlaying <> null)
      {
            
            _root.kirupaSound.start(0,99);      
            isPlaying = null;
            _root.setMyVolume(99);
      }
      else
      {
            _root.kirupaSound.stop();
            isPlaying = "notPlaying";
      }
}
on (volume)
{
      
      _root.setMyVolume(1);
}
ok if you wish to follow Flappi's route, I"ll leave you to it.
good luck.
Avatar of Lico_w

ASKER

I would prefer it if you tried to help me!

All I need is a listener on the volume bar within the controller component, surely that isn't to difficult....is it?
nothing is difficult if you know how.
the way the person did it in the other tutorial is a much better way of doing it but if you don't want to do it that way that's your choice.
Upload your fla and I'll have a look.
Avatar of Lico_w

ASKER

Thanks, I did try it that way but couldn't get it to work.

I have uploaded my fla as requested.
SoundPlayer1.fla
thanks for uploading your file.
you say it works except the volume slider doesn't work?
advise, when i run your file , what actions must I follow to play the sound?
Avatar of Lico_w

ASKER

Using Flash CS4 I just hit CTRL + ENTER to do a publish preview. The component is then partially displayed, I hover my mouse over it to fully display the component and click play. Clicking play again (whilst pause head displayed) stops the sound, but I can live with that.
that's very strange, when i run your file the controller is on the playing state (if I hover over it) and nothing is playing.
i've not used the media controller component before so I'm not sure, maybe it's because you're trying to play a sound from the library. Is this an necessity for what you're trying to achieve?

do you have a link to the original kirupa tutorial?


Avatar of Lico_w

ASKER

No one seems to know about this component!!! So many unresolved posts online regarding it, people seem to just give up! If you crack it they'll have to change your rank to LEGEND!

Anyway here is the tutorial I used initially, if it helps:
http://www.kirupa.com/developer/actionscript/sound.htm
i've changed the other one to load an external sound file and not use xml for you if you want that.  we're all just lowly volunteers here you know.

ahh i thought as much. you notice the tutorial you're following is for AS1 yet your file is AS2? also that tutorial does NOT use the component you want. you cant' at whim mix and match, adobe is not quite there yet.
Avatar of Lico_w

ASKER

To be honest any solution would be good right now, so yes please. Will you post the code on here?

I thought AS2 was backwards compatible? To be honest I don't normally do anything in Flash/Actionscript hence why I just tried to fudge it   ;)

Volunteers??? - You must get paid a good amount though for when you put on a solution?
um we don't get paid squat. not a cent / dollar / dime.
where did you get the idea we get paid.

grab the attached fla , stick a mp3 in the same location. change the name in the code


var myArray:Array = new Array("1.mp3");,

or rename the mp3 to 1.mp3.

run the file, you'll notice that it all works nice and happy.


sound2.fla
Avatar of Lico_w

ASKER

Noooooo, my company security policy won't let me access it! Can you send to my email please?

waynelico@gmail.
Avatar of Lico_w

ASKER

waynelico@gmail.com
um no. let me try zip it. it's against EE policy i think.

oh no, you have to wait till the morning, the file is at work and i'm not redoing it.
ASKER CERTIFIED SOLUTION
Avatar of blue-genie
blue-genie
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lico_w

ASKER

Impressive! Many thanks for your help!

I know you're probably sick to death of me.... But can I just ask you to briefly describe what is going on in the file, does flash automatically run functions in the timelines without them being called?

I know I'm being a pain so if you're to busy I'll post as new question and close this one.
does flash run functions without them being called? No.

if you see there's a function called init =that gets called at the bottom.

init sets some extra variables there that aren't really need since you're only using 1 file (i was lazy) - and it calls the attachController function which places the objects on the stage. You don't need the playNext either unless you want to catch the event when the file is finished playing.

not sure why you weren't able to get the tutorial to work in the first place, maybe a typo or something.

Avatar of Lico_w

ASKER

Very helpful!