| Ultrashock Forums
• Sound volume = mouse proximity? |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
17 Creative Assets
|
2006-08-12
#2 |
||
|
|
|
2006-08-12
#3 |
||
|
Sorry, I'm pretty lame at actionscript. Is that code supposed to be inserted in the timeline? And after this? Code:
this.onLoad = function () {
s_jam = new Sound(this);
s_jam.attachSound("jam");
s_jam.start(0, 999);
s_jam.setVolume(0);
startVol = 100;
}
Code:
var volume:Number = getVolume(_root.myMovieClip, 100); mySound.setVolume(volume); And: Code:
getVolume( targetMovieClip, maxDistance ) So if my mc is called "ball", and if I want the sound to go off at 250 pix, it should be: Code:
getVolume( ball, 250 ) There is also something wrong with the code cause Flash pops up this message:
**Error** Scene=Scene 1, layer=jammed full, frame=1:Line 1: '{' expected Sorry for being so lame. And thank you for your help.
function getVolume( target:MovieClip, maxDistance:Number ):Number { **Error** Scene=Scene 1, layer=jammed full, frame=1:Line 7: Unexpected '}' encountered } Total ActionScript Errors: 2 Reported Errors: 2 |
|
17 Creative Assets
|
2006-08-12
#4 |
||
|
You can just put that code into the first frame of your movie ( i.e. the main time line ). When you want to update the volume of a sound you simply call the getVolume function, so you could use onEnterFrame: ActionScript Code:
|
|
|
|
2006-08-12
#5 |
||
|
Last edited by kindoki : 2006-08-12 at 08:37.
It works! ![]() I created a new .fla and if I use this code in the first frame of the main timeline of scene 1, it works. But if I use the code in the second frame in the same timeline it no longer works. Is it really necessary to use the code on the first frame of the main timeline? I'm asking this because I want to use this in my project, this code is supposed to be used on the second frame of a movie clip inside another movie clip on the main timeline, and it doesn't work. Is there anyway to solve this issue? Thank you very much for your help EDIT h I'm using attachSound BTW, is that what's causing the problem?
|
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


4 comments
| 830 views

17 Creative Assets

h I'm using attachSound BTW, is that what's causing the problem?
Linear Mode
maxDistance is the distance where the volume will be zero. So, if you want the volume to be zero if the mouse is futher than 50px away from the movie clip, then you would pass 50 as the maxDistance value.
Hope that helps.