AS3 tweenlight loop stops - actionscript-3

I have a loop animation that stops and gives me an argument error. I've redone the coding a couple of different ways but to no avail. Here is my code:
contactbox.addEventListener(MouseEvent.MOUSE_OVER, Scroll);
function Scroll(evt:MouseEvent){
TweenLite.to(
btnwave, 2, {
x:-115.5, ease:Linear.easeNone, overwrite:true, onComplete:Switch});
}
function Switch(){
TweenLite.to(
btnwave, 0, {
x:184.6, ease:Linear.easeNone, overwrite:true, onComplete:Scroll});
}
And here is the error it gives me:
ArgumentError: Error #1063: Argument count mismatch on Main/Scroll(). Expected 1, got 0.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.greensock.core::TweenCore/complete()
at com.greensock::TweenLite/renderTime()
at com.greensock::TweenLite()
at com.greensock::TweenLite$/to()
at Main/Switch()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.greensock.core::TweenCore/complete()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
I'm trying to brush up on my tweenlite skills for some upcoming work. Any help would be appreciated.

You're getting an error because TweenLite isn't passing a MouseEvent instance to Scroll(). Scroll() currently requires that a MouseEvent Object be passed to it since it's an event handler. You can fix this by making Scrolls first argument optional like this:
function Scroll(evt:MouseEvent=null){
This way, when TweenLite calls Scroll() the MouseEvent will just default to null.

Related

Error #1063: Argument count mismatch - AS3

I have a very simple animation i want to make but am stuck with these errors
ArgumentError: Error #1063: Argument count mismatch on ReverseCirculation_Complete_Graham_1_ActionScript3_fla::MainTimeline/Play(). Expected 0, got 1.
The idea is an animation will be paused, then clicked on "play" button to start with the ability to stop or pause the animation before clicking "Next" to preview the continued animation.
My code looks like this:
//imports needed
stop();
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Stage;
Play_btn.addEventListener(MouseEvent.CLICK,Play);
Stop_btn.addEventListener(MouseEvent.CLICK,Stop);
Next_btn.addEventListener(MouseEvent.CLICK,Next);
function Play()
{
blue1_mc.play();
red_mc.play();
green_mc.play();
}
function Stop()
{
blue1_mc.stop();
red_mc.stop();
green_mc.stop();
}
function Next(event:MouseEvent):void
{
gotoAndStop(2);
}
Many thanks
Graham
In AS3, when you define a function like so:
function Play()
You are telling it that there are no parameters/arguments for this function. Unlike similar ECMAScript based languages such as JavaScript, if you end up passing a parameter - for example doing Play("Hello") - it will throw an error.
When you setup a event handler, like you do here:
Play_btn.addEventListener(MouseEvent.CLICK,Play);
That event when triggered calls the function specified - Play - and passes it a MouseEvent object that describes the event (such as the object clicked, the mouse position etc.)
Since you've define the Play function to accept no arguments, you get the error saying there's an unexpected argument. (same for the Stop function).
To remedy the issue, you can do 1 of these two things:
Add a MouseEvent argument to the function:
function Play(event:MouseEvent){
Add a MouseEvent argument, but make it optional:
function Play(event:MouseEvent = null){
The second option, means that you can still simply call Play() without passing it an argument.

as3 - Error #1009, an object is null and bugged with timer

When the player touches the door, the next level is supposed to be added and the previous level should be removed. However in the game, the next level does get added and everything works, but the output shows this issue.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
This is the enterframe:
if (player.collisionArea.hitTestObject(door0))
{
var timer: Timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, fade);
timer.reset();
timer.start();
}
This is the timer:
function fade(event: TimerEvent)
{
removeEventListener(TimerEvent.TIMER_COMPLETE, fade);
var pageTwo: PageTwo = new PageTwo;
parent.addChild(pageTwo);
this.parent.removeChild(this);
}
This is in the "previous level" class. "this" is itself (previous level) and "pageTwo" is (next level).
So, the output indicates the error is at "parent.addChild(pageTwo);". However if I remove that, the output indicates the issue is from "this.parent.removeChild(this);
I assume it's because the child is removed that's why there is a null issue. But how do I solve this error coming from the output? Am I removing the movieclip the wrong way?
Your problem is coming from this line :
parent.addChild(pageTwo);
because in your code as this condition
if (player.collisionArea.hitTestObject(door0))
is true, you will create another Timer object which when its TimerEvent.TIMER_COMPLETE event is fired, it will try to add a new PageTwo instance to a null parent and that's why the error is fired.
So to avoid that, you can remove the Event.ENTER_FRAME event listener at the first time when that condition is true or if you still need it (the Event.ENTER_FRAME event listener) you have to verify your condition to avoid such behavior.
Also, your timer var should be declared as global to be accessible from the fade() function to be able to remove its TimerEvent.TIMER_COMPLETE event listener which you are trying to remove from your current object.
Hope that can help.

How to refer to a single frame in a an object class?

So, I have my character movieclip on frame1 of my timeline. When it hits an enemy the movie goes on frame2 where I have a game-over screen. However I get this error at runtime when the character hits the enemy:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Coinsy/update()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_2_fla::MainTimeline/CharMovement()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_2_fla::MainTimeline/ResetBox()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_2_fla::MainTimeline/EnemyBall()
I debugged and it seems that the problem is in my coins class:
package
{
import flash.display.*;
import flash.events.*;
public class Coinsy extends MovieClip
{
var char:MovieClip;
var MTL = MovieClip(root);
public function Coinsy()
{
this.addEventListener(Event.ENTER_FRAME, update);
}
function update(event:Event):void
{
char = MTL.char1;
// CC = int(root).CC;
if(hitTestObject(char))
{
this.removeEventListener(Event.ENTER_FRAME, update);
parent.removeChild(this);
MTL.CC++;
}
}
}
}
at char = MTL.char1;, apparently I can't use MovieClip(root) when I have more then one frame.
char1 is my character's instance name andCC is the coin count var.
I'm pretty new at ActionScript and I'd like to know where i did wrong. THANKS!
The error is actually happening on this line
if(hitTestObject(char))
What's happening is the game is still trying to check for collisions on the game-over screen. The char1 object couldn't be found, so it became null. Null essentially means something's empty, so you can't do anything with it. If you ever try null.something you'll get an error, and someFunction(null) will quite likely cause an error too.
A quick fix is changing the line to
if(char != null && hitTestObject(char))
as Karma mentioned.
However, the following three TypeErrors are unrelated to the code you posted. They're happening because some line of code is trying to do null.something. The CharMovement, ResetBox and EnemyBall functions are probably being called when they shouldn't be. You might need to remove event listeners when game-over happens, or add extra logic to check for null values.

as3 - Constructor Error

I've got (to me) a strange error. As far as I can tell I'm doing everything correct, however I keep getting the error bellow.
ArgumentError: Error #1063: Argument count mismatch on Enemy().
Expected 2, got 0.
As you can see, when initializing my class Enemy it expects two arguments and gets one. However, as far as I can tell it's not the case.
Where it is called.
function startHandle(evt:MouseEvent):void{
enemy = new Enemy(1090, 189);
gotoAndStop(2);
Player.stop();
currentLevel = 1;
}
Then the Enemy class
public function Enemy(xLocation:int, yLocation:int){
trace(xLocation);
trace(yLocation);
// constructor code
x = xLocation;
y = yLocation;
trace(x);
trace(y);
}
The output I get from this is as follows.
1090
189
1090
189
ArgumentError: Error #1063: Argument count mismatch on
Enemy(). Expected 2, got 0.
at flash.display::MovieClip/gotoAndStop()
at
Project_fla::MainTimeline/startHandle()
As far as I can tell it gets the two values, knows it has them, sets them. But still gives an error. Anyone got an idea?
Most likely you have a pre-placed enemy on some frame. Since the default constructor for any DisplayObject descendant wants 0 arguments, anything created in Flash GUI makes Flash compiler to make a constructor call with 0 arguments. To circumvent this (and find that pesky enemy that throws you up) give default values for the constructor like this:
public function Enemy(xLocation:int=0, yLocation:int=0){
And watch when an enemy will appear at (0,0), debug that point and eliminate creation of any unneeded enemy instances.

as3 unload from child

I'm trying to unload a ProLoader from the child.
Code in main.swf
import fl.display.ProLoader;
var myProLoader:ProLoader=new ProLoader();
page2_mc.addEventListener(MouseEvent.CLICK, page2content);
function page2content(e:MouseEvent):void {
var myURL:URLRequest=new URLRequest("page2.swf");
myProLoader.load(myURL);
addChild(myProLoader);
}
function unloadcontent(e:MouseEvent):void {
myProLoader.unload();
}
Code in page2.swf:
return_mc.addEventListener(MouseEvent.CLICK,back);
function back(e:MouseEvent):void{
parent.parent['unloadcontent']();
}
When I run these, I get the following error:
ArgumentError: Error #1063: Argument count mismatch on _09Start_working_fla::MainTimeline/unloadcontent(). Expected 1, got 0. at page2_fla::MainTimeline/back()
I just want the mc in child.swf to unload the content of the ProLoader(back to main).
Thanks for help.
Regards,
Reidar Nygård
Your unloadcontent function expects an argument of type MouseEvent. In order to call it without having to pass one in, change it to:
function unloadcontent(e:MouseEvent = null):void