View Full Version : Question about functions
I should really know this by know but i have always worked around it. How do i define a function that can be called back later during another event. I've seen things like myFunction(); which i take calls an area of code rather than writing it out each time. :confused: :confused: :confused:
senocular
10-31-2007, 03:18 PM
can you be more specific?
FrodoBaggins
10-31-2007, 03:25 PM
function someFunction(arg) {
// do something here
}
someFunction(doStuff);
Is this what you mean?
Cheers for that Frodo. I'll give a good word in at the Shire!! :)
I got this to work before but cant seem to do it again!! Is it any difference when you want to call up a function outside of the event listener?
I have...
function throwBack(arg) {
if (oneHour1Dropped == true){
returnYOneHour1A = new Tween(oneHour, "y", Bounce.easeOut, oneHour.y, 116.7, 1, true);
returnXOneHour1A = new Tween(oneHour, "x", Bounce.easeOut, oneHour.x, 72.5, 1, true);
}
}
//Time setter combo box properties
timeSetter.addEventListener(Event.CHANGE,timeChang e);
function timeChange(event:Event):void {
throwBack(doStuff);
if (timeSetter.value == "0 Minutes"){
countdownTime = 0;
repetitions=0;
myTimer.repeatCount = repetitions;
}}
...I even tried using exatly the same in bracket text as last time!! Can anyone tell me what I am doing wrong.
What on earth!? All I did was changed (doStuff) to (1) and it works, oh well, happy days!:)
stompwampa
11-15-2007, 01:36 PM
well "doStuff" doensn't mean anything to Flash...it was just a term that frodo used as a generic argument...
bolt.PT
11-15-2007, 03:11 PM
Exactly, doStuff is merely representative in that example.
I don't know your complete code, but you don't need that argument in throwback()
Unless you're going to use local variables that you'll need passed to throwback(), you should do it like this:
function throwBack() {
if (oneHour1Dropped == true){
returnYOneHour1A = new Tween(oneHour, "y", Bounce.easeOut, oneHour.y, 116.7, 1, true);
returnXOneHour1A = new Tween(oneHour, "x", Bounce.easeOut, oneHour.x, 72.5, 1, true);
}
}
//Time setter combo box properties timeSetter.addEventListener(Event.CHANGE,timeChang e);
function timeChange(event:Event):void {
throwBack();
if (timeSetter.value == "0 Minutes"){
countdownTime = 0; repetitions=0; myTimer.repeatCount = repetitions;
}
}
Ok guys thanks for making me feel stupid!! :)
I will do that next time. I thought I rememebr adding (doStuff) to something before? Anyway cheers for the tips.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.