Actionascript Timer Errors - actionscript-3

Been working on a game called ChemoBlue for a while now and cannot seem to get rid of this error:
EDIT: I changed a few lines of code and the error is now this:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ChemoBlueSetup/levelUp()[/Users/raphaelhennessy/Desktop/STS/Gold Cinema ChemoBlue/ChemoBlueSetup.as:71]
I used to have a lot more errors thrown at me but now this is the only one. Heres the code that creates the error.
EDIT: I did some debugging and it seems the error comes from here:
public function levelUp(evt:MouseEvent):void
{
if (level == 1)
{
elementName.text = ("water");
gotoAndPlay(1, "Level");
}
else if (level == 2)
{
elementName.text = ("sand");
gotoAndPlay(1, "Level");
}
else if (level == 3)
{
elementName.text = ("???");
gotoAndPlay(1, "Level");
}
}
Thanks in advance,
-Raph

Well I'm not sure if this will fix your problem, but your event listener currently has no parameters. All event listeners must have the event it listens for as a parameter.
So instead of
function frameUp2():void
it should say
function frameUp2(e:TimerEvent):void

It seems I fixed it... in the function levelUp I removed the line making the dynamic text elementName say water if the level was one, which it wouldn't be anyway if that function was executed. Heres the code:
public function levelUp(evt:MouseEvent):void
{
if (level == 1)
{
gotoAndPlay(1, "Level");
}
else if (level == 2)
{
elementName.text = ("sand");
gotoAndPlay(1, "Level");
}
else if (level == 3)
{
elementName.text = ("???");
gotoAndPlay(1, "Level");
}
}
It throws no errors and acts just like I want it to. Thank you everybody!!
-Raph

Related

How to change the behavior of the beforeAction?

There is a beforeAction() in Controller.php
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
}
return true;
}
return false;
}
It throws an exception but I want to change this in my own controller which extends controller.php. I try something like that
public function beforeAction($action) {
if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
Yii::$app->session->setFlash('info', 'Error');
$this->goBack();
}
return parent::beforeAction($action);
}
But it still shows exception.
Not sure but it might work with just changing this row...
$this->goBack();
into...
return $this->goBack();
Another approach would be to catch the Exception from the parent instead. Later there might be other events triggered by beforeAction and if not calling the parent::beforeAction these may not be run as intended.

I am having this Error: Error #1009: Cannot access a property or method of a null object reference

Im having problems with my Game, i seem to be having this error coming out when i try to move to the next keyframe: at InventoryDemo/collision()[InventoryDemo::frame2:123]
I did a debug and it shows me that the error is somewhere here:
addEventListener(Event.ENTER_FRAME, collision)
function collision(event:Event):void{
if(girl.hitTestObject(dust))
{
mushroom.visible = true;
mclick.visible = true;
}
I dont know why the error is coming out
Try this : ( not tested )
addEventListener(Event.ENTER_FRAME, collision)
function collision(event:Event):void{
if(MovieClip(girl).hitTestObject(dust)) {
mushroom.visible = true
mclick.visible = true
}
}
EDIT
Some tests to verify existance of girl object :
trace(girl is DisplayObject) // gives : true
trace(girl is MovieClip) // gives : true
trace(girl.hitTestObject) // gives : function Function() {}

Existence of Movie Clip Boolean without Error 1120

if(stage.contains(mc)){
trace("mc exists");
}
How can I do something along this line without getting an error if "mc" does not exist? I've also tried:
if(mc){
trace("mc exists");
}
You could check mc for null before contains check:
if(mc != null && stage.contains(mc)){
trace("mc exists");
}
Or if you want to check if display object is part of display list, you could use simple function:
function myCheckForStage(object: DisplayObject):Boolean{
return (object != null && object.stage != null)
}

Calling a function inside a function - converting AS2 to AS3

I currently have some code from here (https://github.com/jmhnilbog/Nilbog-Lib-AS2/blob/master/mx/mx/remoting/NetServiceProxy.as) which converts a function into a function. This code is shown below:
private var _allowRes:Boolean= false;
function __resolve( methodName:String ):Function {
if( _allowRes ) {
var f = function() :Object {
// did the user give a default client when he created this NetServiceProxy?
if (this.client != null) {
// Yes. Let's create a responder object.
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
else {
if (typeof(arguments[0].onResult) != "function") {
mx.remoting.NetServices.trace("NetServices", "warning", 3, "There is no defaultResponder, and no responder was given in call to " + methodName);
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
}
if(typeof(this.serviceName) == "function")
this.serviceName = this.servicename;
arguments.unshift(this.serviceName + "." + methodName);
return( this.nc.call.apply(this.nc, arguments));
};
return f;
}
else {
return null;
}
}
Basically what the code is designed to do is return a new function (returned as f) which performs the correct server operates. However, if I try and use this syntax in AS3, I get the following two errors:
Error: Syntax error: expecting semicolon before colon.
Error: Syntax error: else is unexpected.
How would I go about doing this? I know this is someone else's code, but I am trying to get the old AS1/2 mx.remoting functionality working in AS3. Cheers.

Check Mouse Status

I am trying to check when the right button of the mouse is up. I have tried to create an EventListener for RIGHT_MOUSE_UP, but it returns an error (1119: Access of possibly undefined property RIGHT_MOUSE_UP through a reference with static type Class.), while MOUSE_UP doesn't work. How I can do this?
EDIT:
public function mouseOverHandler( evt:MouseEvent )
{
if( evt.buttonDown == true )
{
this.addEventListener( MouseEvent.MOUSE_UP, onMouseRelease);
curState_ = 2;
if( animated_ == true )
{
// Stuff
}
else
{
// Stuff
}
}
else
{
// Stuff
}
dispatchEvent(new CustomButtonEvent(CustomButtonEvent.OVER));
}
check this tip http://www.leebrimelow.com/?p=3253
he said you need FP 11.2 beta for using 'MouseEvent.RIGHT_CLICK' event.