문제

Its a complicated senario for me.

I have a sound management singleton with an asset like dictionary storing all referances to my urls and assets and the guff inside it-

I have a function called addItem(id:String, url:String):Object

I would love to do something similar as soundManager.addItem(id:String, url:String).play() or soundManager.addItem(id:String, url:String).stop() of which it'll both add my item to my dictionary, and begin playing the sound

Currently I do soundManager.addItem(id:String, url:String) then soundManager.play('myID').

My sound asset is an object containing a few bits like Sound, SoundChannel, SoundTransform, URL and some other none descript parts.

I know it will be prototyping - I just get uber stuck when I need to prototype my custom functions and objects.

Thanks in advance


conclusion:

Well, I did do the autoplay as mentioned in my accepted answer.

I also did something pretty cool which I like the look of.

I create a SoundManager class, of which handles and uses a SoundObject of which contains SoundTransform, SoundChannel and anything else Sound object requires.

This way when I add an item to the SoundManager, it'll always return the SoundObject Class that incorporates all the play(), pause(), volume(), position() I need.

Its really very useful and I've already used it on 4 projects! Yey.

Thanks guys for your help.

도움이 되었습니까?

해결책

if you are looking at the code then:

soundManager.addItem(url:String)

is returning an object (which you just added), which is then being given the play() command. you have a few easy options in this.

1) if you always play the sound, then you just add the command into the addItem() function.

2) if you want to do exactly what you have there then you need to make a proper class for the sound object with a play() function. probably one that dispatches an event to soundManager that then switches the sound.

3) add a boolean to the add statement that is an autoplay function, something like:

addItem(value:*, autoPlay:Boolean = false):Object{
if(autoplay) play()
}

다른 팁

what exactly do you mean by "prototyping"? do you mean adding custom methods to a classes prototyp object at runtime? although still possible, that is no longer common practice in AS3 for the following reasons:

  1. not type-safe
  2. bad performance
  3. rarely has any advantage over subclassing.

also, you should pick one method signature for addItem. you listed 3. that's a little confusing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top