actionscript 3 - Calling a function and receiving: "Incorrect number of arguments. Expected 1." -
in small project, made function call function under condition.
import flash.events.event; var yspeed:number=0; var maxspeed:number=5; var accel:number=.1; stage.addeventlistener(event.enter_frame, code); function code(codeevent:event){ if(sprite1.y>449){ code2(); } } function code2(code2event:event):void{ if(yspeed<5){ yspeed+=.5 yspeed-=accel } if(yspeed>5){ yspeed=5 } sprite1.y-=yspeed; trace(yspeed) }
i error:line 9 1136: incorrect number of arguments. expected 1.
on line nine, has code2();
note, have tried doing
code2(event); code2(code2event:event); code2(code2event);
and of them come different errors. tried changing names of function, , adding :void
after calling it.
currently, sprite1's position x=182 , y=482 on stage 320x480
i not have clue on why happening.
when define function parameters not define default values, required (you must provide values parameters when calling function). can solve problem defining default value of null
this:
function code2(code2event:event = null) { // ... }
or providing null
explicitly when calling function so:
code2(null);
as attempts:
code2(event)
- here you're passing reference classevent
rather instance of event class.code2(code2event:event)
- syntax plain wrong, annotate (add:type
) when declaring variables, parameters etc, not when providing values.code2(code2event)
- have been valid if thereevent
instance in code allocated variable namedcode2event
.
all said, doesn't code2()
function needs event provided it, assume mimicked portion above function code()
. can omit , have:
function code2():void { // ... }
Comments
Post a Comment