Issue ArgumentError: Error #1063 - actionscript-3

I create timer class in AS3 name MainTimer.as and I have main.as is use MainTimer class to countdown. When I sent parameters to MainTimer class it error ArgumentError: Error #1063: Argument count mismatch on MainTimer(). Expected 2, got 0. And when I trace(startMin, startSec); in MainTimer show 1 0 . Anybody help.
MainTimer.as
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class MainTimer extends MovieClip {
private var currentMin: int;
private var currentSec: int;
private var oneSecTimer: Timer = new Timer(1000, 1);
public var timerHasStopped: Boolean = false;
public function MainTimer(startMin: int, startSec: int) {
trace(startMin, startSec);
currentMin = startMin;
currentSec = startSec;
minBox.text = String(currentMin);
secBox.text = String(currentSec);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
oneSecTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
oneSecTimer.start();
// trace(currentMin, currentSec);
}
private function onTimerComplete(event: TimerEvent): void {
minBox.text = String(currentMin);
secBox.text = String(currentSec);
//trace(secBox.text);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
currentSec = currentSec - 1;
if (currentSec <= -1) {
currentSec = 59;
currentMin -= 1;
//trace(minBox.text);
}
if (currentMin <= -1) {
timerHasStopped = true;
//resetTimer();
} else {
oneSecTimer.start();
}
}
public function resetTimer(): void {
currentMin = 0;
currentSec = 20;
minBox.text = String(currentMin);
secBox.text = String(currentSec);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
timerHasStopped = false;
oneSecTimer.start();
}
public function increaseTime(): void {
currentSec += 20;
}
}}
main.as
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import MainTimer;
public class main extends MovieClip {
private var startMin: int = 1;
private var startSec: int = 0;
private var gameTimer: MainTimer = new MainTimer(startMin, startSec);
public function main() {
addChild(gameTimer);
}
}}

I think that you have inserted manually an instance of your MainTimer movie clip in the Stage.
So to avoid the #1063 error, you have to remove that instance or simply define default values in your MainTimer class constructor :
// ...
public function MainTimer(startMin:int = 1, startSec:int = 0)
{
// ...
}
// ...
Hope that can help.

package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import MainTimer;
public class main extends MovieClip {
private var startMin: int = 1;
private var startSec: int = 0;
private var gameTimer: MainTimer;
public function main() {
gameTimer = new MainTimer(startMin, startSec);
addChild(gameTimer);
}}}
Try like this it should work :)

Related

1084: error: rightbrace before end of program needed

I'm getting a syntax error but I don't know what is causing the error. I checked all the code, and even re-wrote as new, but I still can't avoid the error.
This is my code :
Code for Avoider.as
package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AvoiderGame extends MovieClip
{
public var enemy:Enemy;
public var avatar:Avvatar;
public var gameTimer:Timer;
public function AvoiderGame()
{
enemy = new Enemy();
addChild( enemy );
avatar = new Avatar();
addChild( avatar );
avatar.x = mouseX;
avatar.Y = mouseY;
gameTimer = new Timer( 25 );
gameTimer.addEventListener( TimerEvent.TIMER, moveEnemyAndAvatar );
gameTimer.start();
}
public function onTick(timerEvent:TimerEvent):void
{
enemy.moveDownABit();
avatar.x = mouseX;
avatar.y = mouseY;
if ( avatar.hitTestObject(enemy) ) { gameTimer.stop(); }
}
}
}
Code for Enemy.as
package
{
import flash.display.MovieClip;
public class Enemy extends MovieClip
{
public function Enemy( startX:Number, startY:Number )
{ x = startX; y = startY;}
public function moveDownABit():void
{ y = y + 3; }
}
}
Code for Avator.as
package
{
import flash.display.MovieClip;
public class Avatar extends MovieClip
{
public function Avatar()
{ /* is an empty function */ }
}
}

AS3 Classes Public Atributte

I am getting an error whenever I try running the game. I get errors for every class saying that the public attribute can only be used inside a package and on this line with "private function moveMe" "the private attribute may only be used on class functions". I verified if I have the as file linked properly. I am not sure what the issue is.
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.Event;
public class banana_fall extends MovieClip {
public function banana_fall (){
var velX:Number=0;
var velY:Number=0;
var falling:Boolean=false;
var gravity:Number=2;
public function banana() {
var timing:Timer = new Timer(20,0);
timing.addEventListener(TimerEvent.TIMER,moveMe);
timing.start();
}
private function moveMe(event:TimerEvent){
this.x=this.x+velX;
this.y=this.y+velY;
if (falling) {
velY=velY+gravity;
}
}
public function setSpot(atX,atY){
this.x=atX;
this.y=atY;
}
//
public function setSpeed(dx,dy){
velX=dx;
velY=dy;
}
}
}
}
The problem is that your public functions were inside your constructor function, which doesnt work in as3.
try this code:
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.Event;
public class banana_fall extends MovieClip {
var velX: Number = 0;
var velY: Number = 0;
var falling: Boolean = false;
var gravity: Number = 2;
public function banana_fall() {
var timing: Timer = new Timer(20, 0);
timing.addEventListener(TimerEvent.TIMER, moveMe);
timing.start();
}
private function moveMe(event: TimerEvent) {
this.x = this.x + velX;
this.y = this.y + velY;
if (falling) {
velY = velY + gravity;
}
}
public function setSpot(atX, atY) {
this.x = atX;
this.y = atY;
}
//
public function setSpeed(dx, dy) {
velX = dx;
velY = dy;
}
}
}

ActionScript3, dropping on stage not working after using MouseEnabled

I'm trying to do do a BattleShip Flash game using ActionScript 3.
1- I draw a grid (class: com.Battleship.grid) using a gridCell:movieClip (class: com.battleship.GridCell)
2- I draw a ship (class: com.battleship.Bateau)
My objective is when I drag the ship to the grid the alpha cell under the mouse changes, and if I drop:
1- if the droptarget is a gridCell, the ship takes place (works fine)
2- if the droptarget is stage, the ship return to originPosition (not working)
My problem: after I used MouseEnabled= false, the ship can drop on the grid, but not on the stage and still dragging.
Here is my code:
var grid:Grid = new Grid(10,new Point(20,20));
var b1:Bateau = new Bateau();
b1.x = 490;
b1.y = 300;
b1.originPos = new Point(b1.x,b1.y);
addChild(b1)
addChild(grid);
package com.battleship {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;
public class Bateau extends MovieClip {
private var _originPos:Point;
public function Bateau() {
originPos = new Point();
buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, onDrag);
}
protected function onDrag(e:MouseEvent):void
{
e.currentTarget.parent.addChild(e.currentTarget);
e.currentTarget.startDrag();
e.currentTarget.mouseEnabled = false;
//e.currentTarget.mouseChildren = false;
addEventListener(MouseEvent.MOUSE_UP, onDrop);
parent.addEventListener(MouseEvent.MOUSE_UP, onDrop);
}
protected function onDrop(e:MouseEvent):void
{
e.currentTarget.mouseEnabled = true;
e.currentTarget.mouseChildren = true;
e.currentTarget.stopDrag();
if(dropTarget == null){
x = originPos.x;
y = originPos.y;
}else{
trace(e.currentTarget.name);
if(dropTarget.parent is GridCell)
{
x = dropTarget.parent.x+20;
y = dropTarget.parent.y;
}
}
}
public function get originPos():Point
{
return _originPos;
}
public function set originPos(originPos:Point):void
{
_originPos = originPos;
}
}
}
package com.battleship {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class GridCell extends MovieClip {
private var _row:int;
private var _col:int;
private var _val:int;
public function GridCell()
{
addEventListener(MouseEvent.CLICK,onClick);
addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
}
public function onClick(e:MouseEvent)
{
//trace("(" + e.currentTarget.row+ ", " + e.currentTarget.col + ")");
trace(e.currentTarget.name);
}
public function onMouseOver(e:MouseEvent)
{
alpha = 0.6;
}
public function onMouseOut(e:MouseEvent)
{
alpha = 1;
}
public function get row():int
{
return _row;
}
public function set row(row:int):void
{
_row = row;
}
public function get col():int
{
return _col;
}
public function set col(col:int):void
{
_col = col;
}
public function get val():int
{
return _val;
}
public function set val(val:int):void
{
_val = val;
}
}
}
package com.battleship {
import flash.geom.Point;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Grid extends Sprite {
private var _size:int;
private var _position:Point;
public function Grid(size:int,position:Point):void
{
_size = size;
_position = position;
var gridCells:Array = new Array(size,size);
var i,j:int;
for(i=0;i<size;i++)
{
gridCells[i] = new Array();
for(j=0;j<size;j++)
{
var cell:GridCell = new GridCell();
cell.row = j+1;
cell.col = i+1;
cell.x = this.position.x + cell.width * (i+1);
cell.y = this.position.x + cell.height * (j+1);
cell.name = "cell" + (j+1) + (i+1);
//cell.addEventListener(MouseEvent.CLICK,onClick);
gridCells[i][j] = cell;
this.addChild(gridCells[i][j]);
}
}
}
public function get size():int
{
return _size;
}
public function set size(size:int):void
{
_size = size;
}
public function get position():Point
{
return _position;
}
public function set position(position:Point):void
{
_position = position;
}
}
}

1067: Implicit coercion of a value of type Class to an unrelated type Function

I'm doing a Flash project for my course. I'm very new and can't seem to get anything to work properly (I gave up on document classes).
My problem is I have a timer, and with each tick it adds to some integers based on a given value. But that isn't the problem, my code will not allow the timer to work, it's in a class called "CounterCode" and when I was getting the timer to go to "CounterA" function it said "Error #1007: Instantiation attempted on a non-constructor" So now I'm sending it to the CounterCode constructor function and It's giving the above error.
I'll give a snippet of the code but ask for more if needed, I've not been doing Flash long so please excuse any cringe worthy code.
public static var turnTimer:Timer = new Timer(500, 100);
turnTimer.addEventListener(TimerEvent.TIMER, CounterCode);
public function CounterCode(Event:TimerEvent):void {
This seems to be where the problem is but I can't seem to figure out what it is, I've searched a lot but it's not really seeming relevant to my problem.
--EDIT WITH FULL CODE--
package {
import Fighter;
import Rogue;
import Mage;
import Healer;
import MonsterOne;
import MonsterTwo;
import MonsterThree;
import MonsterFour;
import turn;
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class CounterCode extends MovieClip {
public static var fighterCount:int = 0;
public static var rogueCount:int = 0;
public static var mageCount:int = 0;
public static var healerCount:int = 0;
public static var fullCount:Number = 100;
public static var monsCount:Number = 0;
public static var whoTurn = String(whoTurn);
public static var turnFighter:MovieClip = turnFighter as MovieClip;
public static var turnRogue:MovieClip = turnRogue as MovieClip;
public static var turnMage:MovieClip = turnMage as MovieClip;
public static var turnHealer:MovieClip = turnHealer as MovieClip;
public static var tGo = new tGo();
public static var turnTimer:Timer = new Timer(500, 100);
turnTimer.addEventListener(TimerEvent.TIMER, CounterCode);
public function CounterCode(Event:TimerEvent):void {
var randChoice;
trace(fighterCount);
fighterCount += Fighter.aSpeed;
rogueCount += Rogue.aSpeed;
mageCount += Mage.aSpeed;
healerCount += Healer.aSpeed;
if(monsCount >= 100) {
whoTurn = "monT";
turnTimer.stop();
randChoice();
}
if(fighterCount >= 100) {
whoTurn = "fighterT";
turnTimer.stop();
trace("stop");
tGo();
}
if(rogueCount >= 100) {
whoTurn = "rogueT";
turnTimer.stop();
tGo();
}
if(mageCount >= 100) {
whoTurn = "mageT";
turnTimer.stop();
tGo();
}
if(healerCount >= 100) {
whoTurn = "healerT";
turnTimer.stop();
tGo();
}
}
}
}
Thank you

AS3 - TypeError # 1009 with Timers

I just have no idea what to do with this. I've been looking through this for an hour now and I keep getting an error reading:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Shooter_Enemy/shotHandler()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
When I debug it it points to the line of the code where "seekingBullet" is added to the stage. Any help resolving this would be greatly welcomed.
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
public class Shooter_Enemy extends MovieClip
{
private var yMove:int = 2;
private var shootTimer:Timer = new Timer(500);
public function Shooter_Enemy()
{
this.name = "mc_shooter_enemy";
this.addEventListener(Event.ENTER_FRAME,enemyMove);
shootTimer.start();
shootTimer.addEventListener(TimerEvent.TIMER,shotHandler);
}
public function addShooterEnemy(X:int):void
{
this.x = X;
this.y = 0;
}
public function removeEnemy()
{
shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler);
shootTimer.stop();
this.removeEventListener(Event.ENTER_FRAME,enemyMove);
this.x = 0;
this.y = (stage.height + this.height);
}
private function shotHandler(te:TimerEvent):void
{
var seekingBullet:SeekingBullet = new SeekingBullet();
Main.seekingBulletArray.push(seekingBullet);
stage.addChild(seekingBullet);
seekingBullet.addSeekingBullet(this.x,this.y);
}
private function enemyMove(e:Event)
{
this.y += yMove;
}
}
}
If it's actual, a good practice for using stage is listening *Event.ADDED_TO_STAGE* and then starting your activity like:
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
public class Shooter_Enemy extends MovieClip
{
private var yMove:int = 2;
private var shootTimer:Timer = new Timer(500);
public function Shooter_Enemy()
{
this.name = "mc_shooter_enemy";
this.addEventListener(Event.ENTER_FRAME,enemyMove);
shootTimer.addEventListener(TimerEvent.TIMER, shotHandler);
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
public function addShooterEnemy(X:int):void
{
this.x = X;
this.y = 0;
}
public function removeEnemy()
{
shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler);
shootTimer.stop();
this.removeEventListener(Event.ENTER_FRAME,enemyMove);
this.x = 0;
this.y = (stage.height + this.height);
}
private function addedToStageHandler(e:Event)
{
shootTimer.start();
}
private function shotHandler(te:TimerEvent):void
{
var seekingBullet:SeekingBullet = new SeekingBullet();
Main.seekingBulletArray.push(seekingBullet);
stage.addChild(seekingBullet);
seekingBullet.addSeekingBullet(this.x,this.y);
}
private function enemyMove(e:Event)
{
this.y += yMove;
}
}
}