• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1146
  • Last Modified:

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;
}
0
Lico_w
Asked:
Lico_w
  • 11
  • 11
1 Solution
 
blue-genieCommented:
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)

0
 
Flappi282Commented:
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
0
 
blue-genieCommented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Lico_wAuthor Commented:
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.
0
 
Lico_wAuthor Commented:
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);
}
0
 
blue-genieCommented:
ok if you wish to follow Flappi's route, I"ll leave you to it.
good luck.
0
 
Lico_wAuthor Commented:
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?
0
 
blue-genieCommented:
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.
0
 
Lico_wAuthor Commented:
Thanks, I did try it that way but couldn't get it to work.

I have uploaded my fla as requested.
SoundPlayer1.fla
0
 
blue-genieCommented:
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?
0
 
Lico_wAuthor Commented:
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.
0
 
blue-genieCommented:
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?


0
 
Lico_wAuthor Commented:
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
0
 
blue-genieCommented:
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.
0
 
Lico_wAuthor Commented:
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?
0
 
blue-genieCommented:
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
0
 
Lico_wAuthor Commented:
Noooooo, my company security policy won't let me access it! Can you send to my email please?

waynelico@gmail.
0
 
Lico_wAuthor Commented:
waynelico@gmail.com
0
 
blue-genieCommented:
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.
0
 
blue-genieCommented:
requires a file called 1.mp3 in same location.
sound2-CS3.zip
0
 
Lico_wAuthor Commented:
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.
0
 
blue-genieCommented:
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.

0
 
Lico_wAuthor Commented:
Very helpful!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 11
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now