mystery Error #1063: Argument count mismatch - actionscript

So I'm getting a "Error #1063: Argument count mismatch" error. The weird thing is that it isn't keeping the game from running, but I would like to know why I'm even getting an error in the first place. The full error is:
ArgumentError: Error #1063: Argument count mismatch on Hock(). Expected 3, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at PlayScreen()[Z:\PROJECTS\Silversound\Occulus Squish\Oculus Squish\Classes\PlayScreen.as:30]
at Main/addPlayscreen()[Z:\PROJECTS\Silversound\Occulus Squish\Oculus Squish\Classes\Main.as:17]
at Main()[Z:\PROJECTS\Silversound\Occulus Squish\Oculus Squish\Classes\Main.as:13]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
The Code for PlayScreen is:
import flashx.textLayout.formats.BackgroundColor;
import flash.display.SimpleButton;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class PlayScreen extends MovieClip
{
public var batArmy:Array;
public var hockArmy:Array;
public var shadow:Shadow;
public var crossHairs:CrossHairs;
var Layer01:MovieClip;
var Layer02:MovieClip;
var Layer03:MovieClip;
var Layer04:MovieClip;
var Layer05:MovieClip;
var randomX:Number = 300 + (660 - 300) * Math.random();
public function PlayScreen()
{
//Mouse.hide();
addBatButton.addEventListener(MouseEvent.CLICK, addBat);
addHockButton.addEventListener(MouseEvent.CLICK, addHock);
batArmy = new Array();
hockArmy = new Array();
//addEventListener(Event.ENTER_FRAME, crossHairsMove);
//stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyPress );
Layer01 = new MovieClip;
this.addChild(Layer01);
Layer02 = new MovieClip;
this.addChild(Layer02);
Layer03 = new MovieClip;
this.addChild(Layer03);
Layer04 = new MovieClip;
this.addChild(Layer04);
Layer05 = new MovieClip;
this.addChild(Layer05);
//add crossHair
/*crossHairs = new CrossHairs(mouseX,mouseY,this);
Layer05.addChild (crossHairs);
addEventListener(Event.ENTER_FRAME, crossHairsMove);*/
}
/*public function onKeyPress( keyboardEvent:KeyboardEvent ):void
{
if ( keyboardEvent.keyCode == Keyboard.DOWN )
{
trace("yar");
addBat;
}
}*/
public function addBat( mouseEvent:MouseEvent ):void
{
var randomX:Number = 300 + (660 - 300) * Math.random();
var newBat = new Bat( randomX, -50, this);
batArmy.push ( newBat );
Layer02.addChild (newBat);
}
public function addHock( mouseEvent:MouseEvent ):void
{
var newHock = new Hock(-72, 170, this);
hockArmy.push ( newHock );
Layer02.addChild (newHock);
}
/*public function crossHairsMove ( e:Event ):void
{
crossHairs.x = mouseX;
crossHairs.y = mouseY;
}*/
}
and from the looks of it the error has something to do with the Hock class, so here's the code for that:
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.ui.Mouse;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
public class Hock extends MovieClip
{
private var _screen: PlayScreen;
public var xSpeed:Number;
public function Hock( startX:Number, startY:Number, screen:PlayScreen )
{
_screen = screen;
x = startX;
y = startY;
width = 100;
scaleY = scaleX;
addEventListener(Event.ENTER_FRAME, moveRightFar);
addEventListener(Event.ENTER_FRAME, moveSpeed)
}
public function moveSpeed( e:Event ):void
{
x += xSpeed;
}
public function moveRightFar ( e:Event): void
{
if (x < 0)
{
gotoAndStop("rollRight");
xSpeed = 13;
}
else if (x >= 240)
{
gotoAndStop("still")
xSpeed = 0;
}
}
}
Now I could be wrong but I think it's having a problem with var newHock = new Hock(-72, 170, this); in the "addHock" function, but I have 3 arguments there, not 0. Right? Anyway, like I said, it's not keeping the game from running but it is kind of annoying, so any insight is welcome. I'm sure it's something obvious. Thanks!

I have a guess, but I'll explain how i got there first ...
the first line of the stacktrace pointing at your source code is
at PlayScreen()[Z:\PROJECTS\Silversound\Occulus Squish\Oculus Squish\Classes\PlayScreen.as:30]
which points at the first line of the constructor of PlayScreen: addBatButton.addEventListener(MouseEvent.CLICK, addBat);
but obviously the problem is not there ...
But PlayScreen extends MovieClip and since you didn't specifically included a super() statement, the compiler will put that at as the first command. In fact, the previous lines of the stack point to the constructor of MovieClip and then to a mysterious constructChildren() method of Sprite
That happens to be an internal method used to create the childs of the Sprite that you might have setup on your clip's stage directly from Animate.
So my guess is, the player is trying to instantiate a symbol that extends Hock and that you positioned on the stage somewhere, and of course is doing it by passing zero arguments because that's what a normal Sprite would expect.
Check your library to see what extends Hock and then see which one of those is placed in some other symbol's stage. Your options then will be to remove that and create it from code or to rework the class signature to take zero arguments.

Related

Reached end of code While Parsinng

I've come across an error saying i've reached the end of the file while parsing. I have an idea as to what to do, but am unsure as to where the missing Bracket should go. Please Help!
package fahrenheit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fahrenheit {
public static void main(String[] args) {
JFrame frame = new JFrame ("Fahrenheit to Celsius");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
FahrenheitPanel panel = new FahrenheitPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public class FahrenheitPanel extends JPanel {
private JLabel inputLabel, outputLabel, resultLabel;
private JTextField fahrenheit;
public FahrenheitPanel() {
inputLabel = new JLabel ("Enter Fahrenheit Temperature:");
outputLabel = new JLabel ("Temperature in Celsius");
resultLabel = new JLabel ("---");
fahrenheit = new JTextField (5);
fahrenheit.addActionListener (new TempListener());
add (inputLabel);
add (fahrenheit);
add (outputLabel);
add (resultLabel);
setPreferredSize (new Dimension (300, 75));
setBackground (Color.yellow);
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
int fahrenheitTemp, celsiusTemp;
String text = fahrenheit.getText();
fahrenheitTemp = Integer.parseInt (text);
celsiusTemp = (fahrenheitTemp-32) * 5/9;
resultLabel.setText (Integer.toString (celsiusTemp));
}
}
}
I am Really unsure as to where i need to place the bracket. PLEASE if someone could help that would be FANTASTIC!
Instead using
Integer.toString(...)
use
String.valueOf(...)
You cannot reference non-static classes in a static class. Make the FahrenheitPanel class static. And the posted code is missing a parenthesis at the very end.

1067: Implicit Coercion of a value

So I'm currently trying to run my collision test on my two sprites, and I'm getting the following error:
C:\\Code\\Game\Game.as, Line 54, Column 34 1067: Implicit coercion of a value of type mvc:PlayerModel to an unrelated type assets.Scripts:SpriteAnimation.
Which is pointing to the following line of code:
handleSpriteToSpriteCollision(_player, _boss);
The function is as follows:
private function handleSpriteToSpriteCollision(sprite1:SpriteAnimation, sprite2:SpriteAnimation):void
{
var toSprite2 : VectorModel = new
VectorModel(0,0,0,0, sprite2.x - sprite1.x, sprite2.y - sprite1.y);
var bitmapData1:BitmapData = new BitmapData(sprite1.width, sprite1.height);
while(testBitmapCollision(sprite1.spriteFrameBitmapData, sprite1.topLeftX, sprite1.topLeftY, sprite2.spriteFrameBitmapData, sprite2.topLeftX, sprite2.topLeftY))
{
sprite2.x -= toSprite2.dx;
sprite2.y -= toSprite2.dy;
}
}
Both sprites display just fine, but as soon as I make the function call it all comes crumbling down. At this point I just need some fresh eyes to take a look at the code to see what's going wrong.
Edit: Here is the PlayerModel.as
package mvc
{
import flash.events.Event;
import flash.events.EventDispatcher;
import assets.Scripts.SpriteAnimation;
public class PlayerModel extends EventDispatcher
{
private var _previousX:Number = 0;
private var _previousY:Number = 0;
private var _xPos:Number = 0;
private var _yPos:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
private var _height:uint = 30;
private var _width:uint;
private var _color:uint;
public function PlayerModel():void
{
}
public function update():void
{
xPos += vx;
yPos += vy;
}
public function get height():uint
{
return _height;
}
public function get color():uint
{
return _color;
}
public function get xPos():Number
{
return _xPos;
}
public function set xPos(value:Number):void
{
_xPos = value;
dispatchEvent(new Event(Event.CHANGE));
}
public function get yPos():Number
{
return _yPos;
}
public function set yPos(value:Number):void
{
_yPos = value;
dispatchEvent(new Event(Event.CHANGE));
}
public function set setX(value:Number):void
{
_previousX = value - vx;
xPos = value;
}
public function set setY(value:Number):void
{
_previousY = value - vy;
yPos = value;
}
}
}
The first thing i would check is the class of your boss and player objects inherit your SpriteAnimation class:
class PlayerModel extends SpriteAnimation
{ ...
Seems as though your handleSpriteToSpriteCollision function is looking for two SpriteAnimations and at least the PlayerModel being passed isn't one
Sprite inherits EventDispatcher so as long as your SpriteAnimation inherits Sprite as well, you shouldn't lose any functionality

AS3 - Error #1009: Cannot access a property or method of a null object reference

I'm getting the following error when trying to run a short piece of code I'm making for use of a particle effect library.
Error #1009: Cannot access a property or method of a null object reference
I originally had my entire code running from Main and it worked fine, when I decided to put it into a "ParticleManager" class I begun getting this error.
The error itself happens here -
stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);
function _onStageMouseDown(e:MouseEvent):void
{
//Draws an explosion on to the screen at the position of the mouse click.
var emitter:Emitter3D = new ParticleExplosion(new Vector3D(mouseX- width/2, mouseY- height/2, 0));
renderer.addEmitter( emitter );
emitter.start();
trace(e);
trace(renderer.mouseX)
trace(renderer.mouseY)
}
}
It occurs on the first line there. And I've tried to research it and found this occurs because the stage is not set to anything, but how do I get around that? Why did it work fine running from Main before hand?
Thanks!
Edit - Additional information requested.
The Main class
package
{
import flash.display.Sprite;
[SWF(width='800', height='600', frameRate='60', backgroundColor='#000000')]
/**
* ...
* #author
*/
public class Main extends Sprite
{
private var pManager:ParticleManager;
public function Main()
{
pManager = new ParticleManager;
}
}
}
The ParticleManager class, which before was identical just named "Main" and would run from that.
package
{
//Flint imports
import flash.events.Event;
import flash.events.MouseEvent;
import org.flintparticles.common.emitters.Emitter;
import org.flintparticles.common.actions.ScaleImage;
import org.flintparticles.common.events.EmitterEvent;
import org.flintparticles.common.events.ParticleEvent;
import org.flintparticles.threeD.emitters.Emitter3D;
import org.flintparticles.threeD.particles.Particle3D;
import org.flintparticles.threeD.renderers.BitmapRenderer;
import org.flintparticles.threeD.renderers.controllers.FirstPersonCamera;
import org.flintparticles.threeD.zones.LineZone;
//Flash imports
import flash.display.Sprite;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Rectangle;
import flash.geom.Vector3D;
/**
* ...
* #author
*/
public class ParticleManager extends Sprite
{
private var orbitter:FirstPersonCamera;
private var renderer:BitmapRenderer;
public function ParticleManager()
{
//Sets up the "BitMapRenderer" a rectangle where the particle effects will be drawn on to
renderer = new BitmapRenderer( new Rectangle( 0, 0, 800, 600 ), false );
renderer.x = 0;
renderer.y = 0;
renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) );
addChild( renderer );
renderer.camera.position = new Vector3D( 0, 0, -400 );
renderer.camera.target = new Vector3D( 0, 0, 0 );
renderer.camera.projectionDistance = 400;
//Mouse click
function addedToStageHandler(event:Event):void
{
stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);
}
function _onStageMouseDown(e:MouseEvent):void
{
//Draws an explosion on to the screen at the position of the mouse click.
var emitter:Emitter3D = new ParticleExplosion(new Vector3D(mouseX- width/2, mouseY- height/2, 0));
renderer.addEmitter( emitter );
emitter.start();
trace(e);
trace(renderer.mouseX)
trace(renderer.mouseY)
}
}
public function removeEmitter( ev:EmitterEvent ):void
{
Emitter3D( ev.target ).removeEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter );
renderer.removeEmitter( Emitter3D( ev.target ) );
}
public function destroy():void
{
for each( var e:Emitter in renderer.emitters )
{
e.stop();
}
}
}
}
Most likely it's not added to stage; therefore, stage is null when the code executes.
Listen for added to stage, then execute that code:
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
function addedToStageHandler(event:Event):void
{
stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);
}
Previously from your Main, it was probably already added to stage.
From Main, I don't see how the particle manager is added to the display list. I believe you just need to add your particle manager to Main:
package
{
import flash.display.Sprite;
[SWF(width = '800', height = '600', frameRate = '60', backgroundColor = '#000000')]
public class Main extends Sprite
{
private var pManager:ParticleManager;
public function Main()
{
pManager = new ParticleManager;
addChild(pManager);
}
}
}

Actionscript 3 Load> Combine> and Save External Images

I'm new to actionscript 3, So Thank you in advance for any help you can give. Bascially what I'm trying to do is load 2 or more external images, all the same size and resolution, then combine or composite them one on top of the other, then save that result as a new image using a jpeg or png encoder.
I don't want to take a snapshot of the stage, I'd like to save the images with thier original resolution. So far the only thing I've been able to do is load two images, and composite them on the stage. thats about it.
Can someone please give some insight into how to accomplish this. I'm using flash pro CS5.5, and writing code in a class file, not on the timeline. Here is a copy of the code.
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
public class imageComposite extends MovieClip
{
var images:Array = ["koala.png","koala2.png"];//two images
public function imageComposite()
{
// constructor code
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
addChild(thumbLoader);
}
thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,bmpData);
}
public function bmpData(evt:Event):void
{
trace("Event was completed successfully!");
}
}
}
First you put both the Loader objects into a separate "holder" object.
// constructor code
var holder:Sprite = new Sprite();
addChild(holder);
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
holder.addChild(thumbLoader);
}
...
Later in your "complete" event handler:
var bitmapData:BitmapData = new BitmapData(holder.width, holder.height, false);
bitmapData.draw(holder);
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
Then you can write this byteArray object to the server or to disk (desktop AIR application).
Thank you so very much for taking the time to offer your knowledge, it was more then helpful. The code you gave me worked perfectly with one exception. the "holder" variable has to be declared outside of the function. I got alittle bit of an access error, but when I placed it outside the function it worked just fine.
Anyway, i've expanded on the code adding the ability to save. I just put a movieClip on the the stage with instance name of "saveButt_mc". Then added the ability to save using fileReference. My goal is to have it autosave to a server using php, but for now this will have to do.
Heres my final code, thanks again for the help.
-D
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.display.Sprite;
import flash.net.FileReference;
import flash.net.FileFilter;
import com.adobe.images.PNGEncoder;
public class imageComposite extends MovieClip
{
var images:Array = ["koala.png","koala2.png"];//two images
var holder:Sprite = new Sprite();
public function imageComposite()
{
// constructor code
addChild(holder);
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader ;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
holder.addChild(thumbLoader);
}
//thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bmpData);
saveButt_mc.addEventListener(MouseEvent.CLICK, bmpData);
addChild(saveButt_mc);
saveButt_mc.buttonMode = true;
}
//need contentLoaderInfo to access loader data;
public function bmpData(evt:Event):void
{
var bitmapData:BitmapData = new BitmapData(holder.width,holder.height,false);
bitmapData.draw(holder);
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
var file:FileReference = new FileReference();
file.save(byteArray, "newImage.jpg");
trace("Event was completed successfully!");
}
}
}

Actionscript 3.0 - Trying to remove a child

Simple simple problem but I can't get it to work.
So I just have a class with a display object, a ball. I create instances of it from Main.as
and run a for loop to check if I hit the ball and if I do, I want to remove the object.
But I can't.
What's wrong with my code?
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends Sprite
{
private var clay:Clay;
private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
private var crash:Crash;
private var crashCollection:Vector.<Crash> = new Vector.<Crash>;
private var timer:Timer = new Timer(0);
private var newClayTimer:Timer = new Timer(1000);
public function Main()
{
newClayTimer.start();
newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);
stage.addEventListener(MouseEvent.CLICK, checkForHit);
}
private function checkForHit(e:MouseEvent):void
{
if (clayCollection.length > 0)
{
for (var i:int = 0; i < clayCollection.length; i++)
{
if (e.target.hitTestObject(clayCollection[i]))
{
clayCollection.splice(i, 1);
removeChild(clayCollection[i]);
}
}
}
}
private function addNewClay(e:TimerEvent):void
{
clay = new Clay();
addChild(clay);
clayCollection.push(clay);
}
}
}
Try something like this
for (var i:int = 0; i < clayCollection.length; i++) {
var clay:Clay = clayCollection[i];
if (e.target.hitTextObject) {
//seems to me all clays will hit test as true with the stage?
removeChild(clay);
clayCollection.splice(i, 1);
}
}
That way you know that the object that you're trying to remove is definitely the one that hit tested true.
I agree with Amy, listen for a click on the instance of clay, not the stage. You can still remove it from your array, something like this (untested code):
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends Sprite
{
private var clay:Clay;
private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
private var crash:Crash;
private var crashCollection:Vector.<Crash> = new Vector.<Crash>;
private var timer:Timer = new Timer(0);
private var newClayTimer:Timer = new Timer(1000);
public function Main()
{
newClayTimer.start();
newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);
}
private function checkForHit(e:MouseEvent):void
{
// identify the target as Clay
var clay:Clay = e.target as Clay;
if(contains(clay)) removeChild(clay);
// remove it from your array
for each (var c:Clay in clayCollection) {
if (c == clay) clayCollection.splice(clayCollection.indexOf(c), 1);
}
}
private function addNewClay(e:TimerEvent):void
{
clay = new Clay();
clay.addEventListener(MouseEvent.CLICK, checkForHit);
addChild(clay);
clayCollection.push(clay);
}
}
}
When the program created a instance of the object and you mouse click it, the debugger threw this error.
Main Thread (Suspended: RangeError: Error #1125: The index 0 is out of range 0.)
Main/checkForHit
The fix is that you need to delimit the index of the loop as you slice it. Also the sequence of when you apply the splice and delimit is important.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends Sprite {
private var clay:Clay;
private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
private var timer:Timer = new Timer(0);
private var newClayTimer:Timer = new Timer(1000);
public function Main(){
newClayTimer.start();
newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);
stage.addEventListener(MouseEvent.CLICK, checkForHit);
}//END MAIN()
private function checkForHit(e:MouseEvent):void{
if (clayCollection.length > 0)
{
for (var i:int = 0; i != clayCollection.length; i++)
{
trace(i,clayCollection.length);
if (e.target.hitTestObject(clayCollection[i]))
{
removeChild(clayCollection[i]);
clayCollection.splice(i, 1);
i--;
}
}
}
}//END checkForHit()
private function addNewClay(e:TimerEvent):void{
clay = new Clay();
addChild(clay);
clayCollection.push(clay);
}//END addNewClay()
}//END MAINCLASS
}//END PACKAGE

Resources