-
Fade in and Fade out with attached sound problem
Hi all,
I've trawled through the forum and there seems to be no definitive answer the problem. I've tried looking for hp3's FAQ as well.
i'm trying to fade out a bit of music that has been attached using action script (attach.sound is the method I think).
Does anybody have code that works that i can stick on my timeline that will fade out (and back in) the attached sound?
Thanks for any help.
D
-
-
Code:
var my_sound:Sound = new Sound();
my_sound.attachSound("visions");
var fadeInPoint = (my_sound.duration*0.2);
var fadeOutPoint = my_sound.duration-(my_sound.duration*0.2);
my_sound.setVolume(0);
my_sound.start();
this.onEnterFrame = function() {
if (my_sound.position<fadeInPoint) {
my_sound.setVolume(my_sound.position/fadeInPoint*100);
} else if (my_sound.position>fadeOutPoint) {
my_sound.setVolume(((my_sound.duration-my_sound.position)/(my_sound.duration-fadeOutPoint))*100);
}
if (my_sound.position>=my_sound.duration) {
delete this.onEnterFrame;
}
};
-
Sorry to be stupid but could you just break down the code for me.
i'm assuming this is to attach the sound? Do I just replace "visions" with my linkage name?
var my_sound:Sound = new Sound();
my_sound.attachSound("visions");
var fadeInPoint = (my_sound.duration*0.2);
var fadeOutPoint = my_sound.duration-(my_sound.duration*0.2);
my_sound.setVolume(0);
my_sound.start();
And is this to just fade in? what do i need to change on this?
this.onEnterFrame = function() {
if (my_sound.position<fadeInPoint) {
my_sound.setVolume(my_sound.position/fadeInPoint*100);
} else if (my_sound.position>fadeOutPoint) {
my_sound.setVolume(((my_sound.duration-my_sound.position)/(my_sound.duration-fadeOutPoint))*100);
}
if (my_sound.position>=my_sound.duration) {
delete this.onEnterFrame;
}
};
-
Do I just replace "visions" with my linkage name?
Yes.
And is this to just fade in?
No, this handles the fade in and fade out.
what do i need to change on this?
Code:
// volume will go from 0 to 100 during the first 20 percent of the sound length
// 'fadeInPoint' determines this position, change '0.2' to change the percentage
var fadeInPoint = (my_sound.duration*0.2);
// volume will go from 100 to 0 during the last 20 percent of the sound length
// 'fadeOutPoint' determines this position, change '0.2' to change the percentage
var fadeOutPoint = my_sound.duration-(my_sound.duration*0.2);
HTH
-
Thanks Dawsonk, i'm half way there.
Can you tell me how to fade it out when it reaches a certain keyframe?
I think it currently fades at a particular percentage of the tune rather than at a key frame.
many thanks.
-
Code:
// place this on the keyframe where fade out is to start
isFadeOutPoint = true;
Code:
// main time line first frame
var my_sound:Sound = new Sound();
my_sound.attachSound("visions");
var fadeInPoint = (my_sound.duration*0.2);
var isFadeOutPoint = false;
my_sound.setVolume(0);
my_sound.start();
this.onEnterFrame = function() {
if (my_sound.position<fadeInPoint) {
my_sound.setVolume(my_sound.position/fadeInPoint*100);
} else if (isFadeOutPoint) {
if (fadeOutPoint == undefined) {
fadeOutPoint = _currentframe;
}
my_sound.setVolume(((my_sound.duration-my_sound.position)/(my_sound.duration-fadeOutPoint))*100);
}
if (my_sound.position>=my_sound.duration) {
delete this.onEnterFrame;
}
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|