开发者

prototype functions off custom functions

开发者 https://www.devze.com 2022-12-23 17:11 出处:网络
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-

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 woul开发者_运维问答d 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消