Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ENTER_FRAME return values

New Here ,
Feb 24, 2008 Feb 24, 2008
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


TOPICS
ActionScript
595
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 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...
Translate
Community Expert ,
Feb 24, 2008 Feb 24, 2008
you can't get a return from a listener function. put your trace inside getGreenInfo or dispatch greenNumber where it's needed.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2008 Feb 24, 2008
and yes, you can return multiple variables/values from a function using an object or array, for example, as the return type.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2008 Feb 24, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
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, 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:
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 25, 2008 Feb 25, 2008
chris? who's chris? ;)

yes you definitely can have multiple &&'s within one statement.

currentFrame will never equal 0, the first frame is 1.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines