Forums

ForumsProgramming Forum

Confused?

Posted Apr 29, '13 at 4:04pm

alex57834

alex57834

89 posts

I have got the error
C:\\Users\\Alex The Best\\Desktop\\Golden Catch\\Classes\\MainGame.as, Line 28 1137: Incorrect number of arguments. Expected no more than 0.

package {

import flash.display.MovieClip;

public class GoldBar extends MovieClip {

public var xSpeed:Number;
public var ySpeed:Number;
public var randomX:Number;


public function GoldBar(startX:Number, startY:Number):void
{

randomX:Number = Math.random()*550;

startX = randomX;
startY = -20;

xSpeed = 0.
ySpeed = 3.
}

public function moveDown():void
{
y = y + ySpeed;
}

}

}

package {

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class MainGame extends MovieClip {

public var army:Array;
public var goldBar:GoldBar;
public var gameTimer:Timer;

public function MainGame()
{
army = new Array();

gameTimer = new Timer(25);
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();

}

public function onTick(e:TimerEvent):void
{
if( Math.random () < 0.08 )
{
public var newGoldBar = new GoldBar(startX ,startY);
army.push(newGoldBar);
addChild (newGoldBar);

for each (var goldBar:GoldBar in Army)
{
goldBar.moveDown();
}
}
}

}

}

 

Posted Apr 29, '13 at 7:40pm

weirdlike

weirdlike

989 posts

Moderator

well.. I notice a few errors like this line public var newGoldBar = new GoldBar(startX ,startY); in your onTick function shouldn't be public take that out and you declare your public var goldBar:GoldBar; with the name as same but lowercase g in goldBar but the on tick function shows it as being capital G in goldBar. using the same var name but with one difference like a capital versus non capital can be too confusing

and your for each (newGoldBar in army ) you were creating a in army "case sensitive"


a little confusing maybe but try looking at this in your main package

private var gb:GoldBar //gb instead of goldBar

and your onTick
if ( Math.random() < 0.08 )
{
//cut out the randomX function in your gold bar package and just
//added it here because it represents the class and is
//not a function
var randomX:Number = Math.random() * 500;

var gb = new GoldBar(randomX, -20);

army.push(gb);
addChild(gb);

}
for each (gb in army) //lookie change here
{
//Leave the move down function as it is a real function
gb.moveDown();
}

in your gold bar package change this public var ySpeed:Number;
to this public var ySpeed:Number=3;

 

Posted Apr 29, '13 at 7:46pm

weirdlike

weirdlike

989 posts

Moderator

more specifically the error you are getting is from the line

public var newGoldBar = new GoldBar(startX ,startY);

startX and startY

flash doesn't know what it is

 

Posted Apr 30, '13 at 12:18pm

alex57834

alex57834

89 posts

I changed everything and I still have the same error

package {

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class MainGame extends MovieClip {

public var army:Array;
public var gb:GoldBar;
public var gameTimer:Timer;

public function MainGame()
{
army = new Array();

gameTimer = new Timer(25);
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();

}

public function onTick(e:TimerEvent):void
{
if( Math.random () < 0.08 )
{

var randomX:Number = Math.random() * 500;
var gb = new GoldBar(randomX , -20);
army.push(newGoldBar);
addChild (newGoldBar);

for each (var gb in Army)
{
gb.moveDown();
}
}
}

}

}

package {

import flash.display.MovieClip;

public class GoldBar extends MovieClip {

public var xSpeed:Number = 0;
public var ySpeed:Number = 3;

public function GoldBar()
{

}

public function moveDown():void
{
y = y + ySpeed;
}

}

}

 

Posted Apr 30, '13 at 12:21pm

alex57834

alex57834

89 posts

edit: army.push(gb);
addChild (gb);

 

Posted Apr 30, '13 at 12:58pm

weirdlike

weirdlike

989 posts

Moderator

I guess I should have ran the code before replying and was assuming other factors were at play here

use same code as above and change onTick like so

var randomX:Number = Math.random() * 500;
var gb = new GoldBar();
gb.x=randomX;
gb.y=-20;
army.push(gb);
addChild (gb);

for each (gb in army)
{
gb.moveDown();
}

 

Posted Apr 30, '13 at 1:15pm

weirdlike

weirdlike

989 posts

Moderator

after playing around with the code a little I think I am starting to understand what you are trying to achieve

1137: Incorrect number of arguments. Expected no more than 0.

there was actually nothing there telling what the x and y coordinates were so you need to tell it where it is by adding the coordinate in the main GoldBar constructor

//MainGame
var gb = new GoldBar(randomX, -20);

//GoldBar
public function GoldBar(startX:Number, startY:Number)
{
x = startX;
y = startY;
}

 

Posted Apr 30, '13 at 3:39pm

alex57834

alex57834

89 posts

You have helped loads, I got another error relating to arguments and fixed it(because of your teaching) but this is confusing me

I deleted the public var but that didn't help.

C:\\Users\\Alex The Best\\Desktop\\Golden Catch\\Classes\\MainGame.as, Line 27 Warning: 3596: Duplicate variable definition.

package {

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class MainGame extends MovieClip {

public var army:Array;
public var gameTimer:Timer;

public function MainGame()
{
army = new Array();

gameTimer = new Timer(25);
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();

}

public function onTick(event:TimerEvent):void
{
if( Math.random () < 0.08 )
{
var randomX:Number = Math.random()*550;
var gb = new GoldBar();
gb.x = randomX;
gb.y = -20;
army.push(gb);
addChild(gb);
}

for each (var gb:GoldBar in army)
{
gb.moveDown();
}
}

}

}

package {

import flash.display.MovieClip;
import flash.events.Event;

public class GoldBar extends MovieClip {

public function GoldBar()
{

}

public function moveDown():void
{
y = y + 2;
}

}

}

 

Posted Apr 30, '13 at 4:28pm

weirdlike

weirdlike

989 posts

Moderator

I am thinking it is because the variable is declared inside the function so other functions actually don't know what it is and that is why it must be declared outside the function

put this back
public var army:Array;
public var gb:GoldBar; //declare it here
public var gameTimer:Timer;

and call to it
public function onTick(event:TimerEvent):void
{
if( Math.random () < 0.08 )
{
var randomX:Number = Math.random()*550;
gb = new GoldBar(); // see the declared variable from above
gb.x = randomX;
gb.y = -20;
army.push(gb);
addChild(gb);
}

for each (gb in army) //it can see it here too
{
gb.moveDown();
}
}

 

Posted May 1, '13 at 1:43am

alex57834

alex57834

89 posts

Thanks you have really helped and it's quite easy to understand the way you explain it. I'll send a message to show you game when it's done

 
Reply to Confused?

You must be logged in to post a reply!