• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Error Help..

Community Beginner ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at AttackMC/frame25()

what do ii do?

What does this mean?

if ii put ...

stop();

trace("parent: " + parent);

trace("mc parent: " + MovieClip(parent));

MovieClip(parent).gotoAndPlay(MovieClip(parent).currentFrame+1);

to trace it out the following comes out...

parent: null

mc parent: null

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at AttackMC/frame25()

____

so..

ii am using Flash player 10

how do ii give it a parent.. so that it works..

In the library the movieclip is called Attack and then their is a linkage AttackMC

is that the problem?

TOPICS
ActionScript

Views

598

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

I am going to guess that you removed the line addChild(Attack) from your code from earlier.  You originally said you added that to make it play, but that is not what it does,  What it does is adds it to the stage so that it then has a parent (the main timeline).  If you do not use the addChild() command, the movieclip will still play if you tell it to, and without a parent it will fail with the error you are getting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

objectMove.addEventListener(Event.ENTER_FRAME, testHit);

function testHit(event:Event):void

{

          var Attack:AttackMC = new AttackMC();

 

          if (objectMove.hitTestObject(objectWall))

          {

                    objectMove.removeEventListener(Event.ENTER_FRAME, testHit);

                    addChild(Attack);

          }

}

that what you mean?

Thats on the maintimeline and then the Attack is a movieclip in the library

And that is the coding for the Attack movieclip

import flash.display.MovieClip;

 

stop();

trace("parent: " + parent);

trace("mc parent: " + MovieClip(parent));

MovieClip(parent).gotoAndPlay(MovieClip(parent).currentFrame+1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

It is as I suggested. 

              var Attack:AttackMC = new AttackMC();

With that line where it is you are likely creating hundreds of those AttackMC objects before you actually generate a hitTest.  But the only one that gets the addChild() working for it is the one that gets added when the hitTest passes.

So the first of the hundreds that you create  that plays to its end will produce the error you are getting since it was never added to the stage.

You do not want to be instantiating new instances every time that function gets called, and that function gets called at the frame rate of your file.  Just put a trace command in right after that line and see how many of those you end up creating before your hitTest finds a hit.

You should declare that outside of the function and instantiate it only once inside the conditional.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

ii get over a couple of screen full of them..

do ii just move it or recode it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 13, 2012 Apr 13, 2012

Copy link to clipboard

Copied

LATEST

I already answered that in the last sentence of my last response.  You can do a little bit of both.  What you should do is think about what you need to do with it.  Where you have that line now you can see what it does.  You only want to create one when you need it. 

I feel people learn from working things thru rather than being handed solutions, so that why I am not handing you the code that would fix it.  It is a simple change, involving a simple concept that you should get under your belt.  working thru it will help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines