# Using function

**URL:** <https://forum.kirupa.com/t/using-function/18603>\
**Category:** Uncategorized\
**Created:** [April 18, 2003, 3:13pm UTC](https://forum.kirupa.com/t/using-function/18603 "2003-04-18T15:13:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazygamer](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@crazygamer](https://forum.kirupa.com/u/crazygamer)\
**Post date:** [April 18, 2003, 3:13pm UTC](https://forum.kirupa.com/t/using-function/18603/1 "2003-04-18T15:13:31Z")

</div>

can i just call up a function without it being in an onsomethingevent type thing…because i have a function called choosetrack, and i want it to do what the function is supposed to do, which is select a track for my sound player to play…however, i have the function being initiated on a onSoundComplete…and i need it to initiate as soon as my movie loads…and then again after the sound finishes…and then again…and again…  
anyways…i have the again part down…i just need to start it right away  
can anyone help?  
TIA

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 4:21pm UTC](https://forum.kirupa.com/t/using-function/18603/2 "2003-04-18T16:21:51Z")

</div>

Just call your function on frame one…

function startyoursound(){  
//code and whatever  
}  
startyoursound();

That way when frame 1 gets hit, the function will be activated.

Well… that is if your movie STARTS on frame one, if not, then just call your function on whatever frame your animation starts on.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 4:37pm UTC](https://forum.kirupa.com/t/using-function/18603/3 "2003-04-18T16:37:33Z")

</div>

hei crazygamer!! i’m interested with your function choosetrack…  
can i see it??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 4:44pm UTC](https://forum.kirupa.com/t/using-function/18603/4 "2003-04-18T16:44:40Z")

</div>

ok, here’s the code for the whole frame with my sounds…i have 3 files that I uploaded to my website…and I have flash load them up in order and play them…  
[AS]  
tracktoplay = 1;  
function choosetrack() {  
track = new Sound();  
if (tracktoplay == 3) {  
tracktoplay = 1;  
} else {  
tracktoplay += 1;  
}  
if (tracktoplay == 1) {  
\_root.audioMC.gotoAndPlay(1);  
track.loadSound(“[http://www.flashtek.devisland.net/intheend.mp3](http://www.flashtek.devisland.net/intheend.mp3)”, false);  
}  
if (tracktoplay == 2) {  
\_root.audioMC.gotoAndPlay(1);  
track.loadSound(“[http://www.flashtek.devisland.net/silverandcold.mp3](http://www.flashtek.devisland.net/silverandcold.mp3)”, false);  
}  
if (tracktoplay == 3) {  
\_root.audioMC.gotoAndPlay(1);  
track.loadSound(“[http://www.flashtek.devisland.net/dmxxgon.mp3](http://www.flashtek.devisland.net/dmxxgon.mp3)”, false);  
}  
track.onLoad = function() {  
\_root.audioMC.gotoAndStop(3);  
track.start();  
};  
track.onSoundComplete = choosetrack;  
}  
track = new Sound();  
\_root.audioMC.gotoAndPlay(1);  
track.loadSound(“[http://www.flashtek.devisland.net/intheend.mp3](http://www.flashtek.devisland.net/intheend.mp3)”, false);  
track.onLoad = function() {  
\_root.audioMC.gotoAndStop(3);  
track.start();  
};  
track.onSoundComplete = choosetrack;  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 4:46pm UTC](https://forum.kirupa.com/t/using-function/18603/5 "2003-04-18T16:46:20Z")

</div>

whoa…looks scary now that I see it…i’m amazing…NOT 🙂  
OK I have another question…all of the code above is in a frame on the main timeline…I have a movie clip also on the main timeline…and a fastforward button in that movie clip…how can I access the choosetrack function from my button…whould it be \_root.choosetrack ();  
???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 4:58pm UTC](https://forum.kirupa.com/t/using-function/18603/6 "2003-04-18T16:58:05Z")

</div>

thank’s… i think your function has to many repetition that can be shorted by array and can be simplified… i guess:)  
but i’m not the one who able to do it…😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 5:27pm UTC](https://forum.kirupa.com/t/using-function/18603/7 "2003-04-18T17:27:13Z")

</div>

i didn’t test this… but it should give you an idea on how to make it easier. 😉

```auto
var i = 0, tracks = ["intheend.mp3", "silverandcold.mp3", "dmxxgon.mp3"];
Sound.prototype.chooseTrack = function() {
	i++%tracks.length;
	this.loadSound("http://www.flashtek.devisland.net/"+tracks*, false);
	this.onLoad = function() {
		this.start();
	};
	this.onSoundComplete = chooseTrack;
};

```

hope it helps. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 5:31pm UTC](https://forum.kirupa.com/t/using-function/18603/8 "2003-04-18T17:31:18Z")

</div>

there u are… like i said before…  
where have u been kax??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 5:38pm UTC](https://forum.kirupa.com/t/using-function/18603/9 "2003-04-18T17:38:38Z")

</div>

on vacation!! =)

i was really tired of my life, spending all day in front of the computer. 😛

**edit.** but now i’m really glad to be back. 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 5:41pm UTC](https://forum.kirupa.com/t/using-function/18603/10 "2003-04-18T17:41:17Z")

</div>

wish could do that too ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 18, 2003, 5:45pm UTC](https://forum.kirupa.com/t/using-function/18603/11 "2003-04-18T17:45:50Z")

</div>

sorry man. :-\

but i can’t help it… i’m so glad! as good as new!! =)
