0
New Here
,
/t5/animate-discussions/enter-frame-return-values/td-p/346990
Feb 24, 2008
Feb 24, 2008
Copy link to clipboard
Copied
I'm trying to return a value from a function but I keep
getting this error: "Incorrect Number of Arguments. Expected 1." I
think there should be a pretty easy solution to this one but I just
don't know what it's asking for here. I assumed it wanted the name
of the variable I was trying to return but that wasn't right.
Here's the code. Also, is it possible to return more than one value
from a single function?
Thanks,
Joe
Thanks,
Joe
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Advisor
,
Feb 24, 2008
Feb 24, 2008
joe,
afraid your code's getting worse!
there's three main issues -
1. as kglad said, "you can't get a return from a listener function". this means that your getGreenInfo function should return void, NOT Number.
2. this also means that your event handler(aka listener function) should not have the following line:
return greenNumber;
3. but wait! the return is actually stopping your trace line from being called. but your trace line at the moment:
trace(getGreenInfo());
is self-referential, meani...
afraid your code's getting worse!
there's three main issues -
1. as kglad said, "you can't get a return from a listener function". this means that your getGreenInfo function should return void, NOT Number.
2. this also means that your event handler(aka listener function) should not have the following line:
return greenNumber;
3. but wait! the return is actually stopping your trace line from being called. but your trace line at the moment:
trace(getGreenInfo());
is self-referential, meani...
Community Expert
,
/t5/animate-discussions/enter-frame-return-values/m-p/346991#M9397
Feb 24, 2008
Feb 24, 2008
Copy link to clipboard
Copied
you can't get a return from a listener function. put your
trace inside getGreenInfo or dispatch greenNumber where it's
needed.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/animate-discussions/enter-frame-return-values/m-p/346992#M9398
Feb 24, 2008
Feb 24, 2008
Copy link to clipboard
Copied
and yes, you can return multiple variables/values from a
function using an object or array, for example, as the return
type.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
JoeLongstreet
AUTHOR
New Here
,
/t5/animate-discussions/enter-frame-return-values/m-p/346993#M9399
Feb 24, 2008
Feb 24, 2008
Copy link to clipboard
Copied
Alright, I've changed my code from this:
function getGreenInfo(event:Event):Number {
var greenNumber:Number;
greenNumber = greenBar.currentFrame;
return greenNumber;
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
trace(getGreenInfo());
to this:
function getGreenInfo(event:Event):Number {
var greenNumber:Number;
return greenNumber;
trace(getGreenInfo());
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
but my trace statement within my function returns nothing
function getGreenInfo(event:Event):Number {
var greenNumber:Number;
greenNumber = greenBar.currentFrame;
return greenNumber;
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
trace(getGreenInfo());
to this:
function getGreenInfo(event:Event):Number {
var greenNumber:Number;
return greenNumber;
trace(getGreenInfo());
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
but my trace statement within my function returns nothing
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advisor
,
/t5/animate-discussions/enter-frame-return-values/m-p/346994#M9400
Feb 24, 2008
Feb 24, 2008
Copy link to clipboard
Copied
joe,
afraid your code's getting worse!
there's three main issues -
1. as kglad said, "you can't get a return from a listener function". this means that your getGreenInfo function should return void, NOT Number.
2. this also means that your event handler(aka listener function) should not have the following line:
return greenNumber;
3. but wait! the return is actually stopping your trace line from being called. but your trace line at the moment:
trace(getGreenInfo());
is self-referential, meaning that it is calling the function it is in, and your computer will hang for a little while until flash works out there's a never-ending loop.
so anyway, what are you trying to do? if you want to trace the currentFrame of greenbar every frame, then this will suffice:
afraid your code's getting worse!
there's three main issues -
1. as kglad said, "you can't get a return from a listener function". this means that your getGreenInfo function should return void, NOT Number.
2. this also means that your event handler(aka listener function) should not have the following line:
return greenNumber;
3. but wait! the return is actually stopping your trace line from being called. but your trace line at the moment:
trace(getGreenInfo());
is self-referential, meaning that it is calling the function it is in, and your computer will hang for a little while until flash works out there's a never-ending loop.
so anyway, what are you trying to do? if you want to trace the currentFrame of greenbar every frame, then this will suffice:
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
JoeLongstreet
AUTHOR
New Here
,
/t5/animate-discussions/enter-frame-return-values/m-p/346995#M9401
Feb 25, 2008
Feb 25, 2008
Copy link to clipboard
Copied
Craig,
Thank you so much for your help. I'm new at this actionScript thing so whenever I can get somebody to take a second and actually explain what is going wrong, it really helps me out a lot. I was just making it a little more difficult than it had to be.
I have 5 movie clips on stage and if two of them are at frame 10, I want the movie to go somewhere else and play. So my code will look something like this:
function getGreenInfo(event:Event):void {
if (greenBar.currentFrame == 10 && yellowBar.currentFrame == 10 && whiteBar.currentFrame == 0) {
trace("Underpants");
}
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
This doesn't really work, I'm guessing you can't have multiple &&'s within one statement?
Thanks again Chris for your explanation.
Joe
Thank you so much for your help. I'm new at this actionScript thing so whenever I can get somebody to take a second and actually explain what is going wrong, it really helps me out a lot. I was just making it a little more difficult than it had to be.
I have 5 movie clips on stage and if two of them are at frame 10, I want the movie to go somewhere else and play. So my code will look something like this:
function getGreenInfo(event:Event):void {
if (greenBar.currentFrame == 10 && yellowBar.currentFrame == 10 && whiteBar.currentFrame == 0) {
trace("Underpants");
}
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
This doesn't really work, I'm guessing you can't have multiple &&'s within one statement?
Thanks again Chris for your explanation.
Joe
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advisor
,
/t5/animate-discussions/enter-frame-return-values/m-p/346996#M9402
Feb 25, 2008
Feb 25, 2008
Copy link to clipboard
Copied
chris? who's chris? ;)
yes you definitely can have multiple &&'s within one statement.
currentFrame will never equal 0, the first frame is 1.
yes you definitely can have multiple &&'s within one statement.
currentFrame will never equal 0, the first frame is 1.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
JoeLongstreet
AUTHOR
New Here
,
LATEST
/t5/animate-discussions/enter-frame-return-values/m-p/346997#M9403
Feb 25, 2008
Feb 25, 2008
Copy link to clipboard
Copied
How embarrassing. I had your name right in front of me and I
couldn't get it straight. At least I got your name right on the
first part of the post. Thanks again for the help, Craig.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

