Solved

Flash CS4 - Actionscript - Media Controller

Posted on 2010-09-07
23
1,117 Views
Last Modified: 2013-11-11
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
Comment
Question by:Lico_w
  • 11
  • 11
23 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 33634674
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
 
LVL 3

Expert Comment

by:Flappi282
ID: 33641604
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33643780
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
 

Author Comment

by:Lico_w
ID: 33647000
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
 

Author Comment

by:Lico_w
ID: 33647635
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33647743
ok if you wish to follow Flappi's route, I"ll leave you to it.
good luck.
0
 

Author Comment

by:Lico_w
ID: 33660232
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33660257
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
 

Author Comment

by:Lico_w
ID: 33660306
Thanks, I did try it that way but couldn't get it to work.

I have uploaded my fla as requested.
SoundPlayer1.fla
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33660465
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
 

Author Comment

by:Lico_w
ID: 33660564
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 39

Expert Comment

by:blue-genie
ID: 33660699
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
 

Author Comment

by:Lico_w
ID: 33660745
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33661034
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
 

Author Comment

by:Lico_w
ID: 33661315
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33661836
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
 

Author Comment

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

waynelico@gmail.
0
 

Author Comment

by:Lico_w
ID: 33662231
waynelico@gmail.com
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33664996
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
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 33669538
requires a file called 1.mp3 in same location.
sound2-CS3.zip
0
 

Author Comment

by:Lico_w
ID: 33670064
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33670220
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
 

Author Closing Comment

by:Lico_w
ID: 33670258
Very helpful!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

707 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

18 Experts available now in Live!

Get 1:1 Help Now