Jump to content
Search Community

Problems Tweening a SoundTransform - please help

Eckstein1 test
Moderator Tag

Recommended Posts

I'm using the following code to tween a sound. Unfortunatelly I'm getting an error message:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

import com.greensock.TweenMax; 

// create a MP3Loader that will begin playing immediately when it loads
var loader:MP3Loader = new MP3Loader("sounds/sound1.mp3", {name:"loader", autoPlay:true, repeat:-1, volume:0, onComplete:soundLoaded});

// begin loading
loader.load();

function soundLoaded(e1:LoaderEvent):void {
//	// tween volume by volume plugin - works fine, use loader object for tween
//	TweenMax.to(e1.target, 5, {volume:1, repeat:-1, yoyo:true}); 

// tween volume and pan by soundTransform plugin - crashes, use channel for tween
e1.target.channel.soundTransform = new SoundTransform(0, -1);
TweenMax.to(e1.target.channel, 5, {soundTransform:{volume:1, pan:1}, repeat:-1, yoyo:true}); 

//TypeError: Error #1034: Typumwandlung fehlgeschlagen: NaN kann nicht in flash.media.SoundTransform umgewandelt werden.
//	at com.greensock::TweenMax/renderTime()
//	at com.greensock.core::SimpleTimeline/renderTime()
//	at com.greensock::TweenLite$/updateAll()
}

 

Am I using the correct objects to tween? Is there anything else I'm doing wrong?

 

Thanks a lot for your help in advance,

Uli

 

PS: I'm using the latest version of TweenMax.

Link to comment
Share on other sites

The SoundTransformPlugin essentially allows you to target the soundTransform property of an object, in the same way that { x:100 } would tween an object's x property. Since e1.target.channel does have a soundTransform property, your tween is perfectly formed.

 

{ volume:1 } is working because VolumePlugin is activated by default in TweenMax, however, SoundTransformPlugin requires manual activation:

 

import com.greensock.plugins.*;
TweenPlugin.activate([soundTransformPlugin]);

Without the plugin activated, TweenMax will try to set the soundTransform property to {volume:1, pan:1}, which doesn't work since this is a generic object, and soundTransform is expecting a SoundTransform object.

 

I hope that's not confusing. Just activate the plugin and you should be fine.

Link to comment
Share on other sites

Hi jamiejefferson,

 

thanks a lot for your reply and it works great for sounds - life can be so easy...

 

Now I try the same with a video and it's embedded sound, but again I can't get it working:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

import com.greensock.TweenMax; 
import com.greensock.plugins.*;

TweenPlugin.activate([soundTransformPlugin]); // now it's there

// create a VideoLoader that will begin playing immediately when it loads
var loader:VideoLoader = new VideoLoader("videos/video3.mp4", {name:"loader", container:this, width:400, height:300, scaleMode:"proportionalInside", bgColor:0x000000, autoPlay:true, volume:1, requireWithRoot:this.root, onComplete:videoLoaded});

// begin loading
loader.load();

function videoLoaded(e1:LoaderEvent):void {
//	// tween volume by volume plugin - works fine, use loader object for tween
//	TweenMax.to(e1.target, 5, {volume:1, repeat:-1, yoyo:true}); 

// volume init:1, try to set it to 0, but doesn't work
e1.target.content.soundTransform = new SoundTransform(0, -1);
// try tween, but doesn't work - where do I find the channel object?
TweenMax.to(e1.target.content, 5, {soundTransform:{volume:1, pan:1}, repeat:-1, yoyo:true});
}

 

Where do I find the channel of a video? Which object should I use instead If there's none available?

 

Thanks again,

Uli

Link to comment
Share on other sites

I think you want to access the loader's netStream for this. I had a look at the internals of VideoLoader, and the volume plugin applies volume changes to the netStream, so it's fair to say this should work.

 

e1.target.netStream.soundTransform = new SoundTransform(0, -1);
TweenMax.to(e1.target.netStream, 5, {soundTransform:{volume:1, pan:1}, repeat:-1, yoyo:true});

Please be aware however, that VideoLoader has it's own volume member variable, which will report different values after you directly alter netStream.soundtransform e.g.

 

trace(e1.target.volume); // 1
e1.target.netStream.soundTransform = new SoundTransform(0, -1); // sets volume to 0
trace(e1.target.volume); // 1 (expecting 0)
TweenMax.to(e1.target.netStream, 5, {soundTransform:{volume:1, pan:1}, repeat:-1, yoyo:true}); // works as expected

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...