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

Why am I getting error 1118 here?

Explorer ,
Apr 02, 2014 Apr 02, 2014

In the code below I have several MovieClips that are all TheBeetle(). They are in another MovieClip called gamelevel and also pushed in an array called bArray. previously I have indexed them in the gamelevel but after the event listener is called I cannot index them anymore and receive the error "1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.". As the user clicks them, they die (and change the frame) and the dead body goes under other alive bodies, thats the reason I need to index them to 1 as they die. I understand what the error says but how can i do what i need to do?

The code works just fine but it wouldn't in the two lines i've mentioned in it, so take a look please:

    public function clicked (event:MouseEvent)

        {

            if (event.target is TheBeetle && event.target.currentFrame <= 2)

            {

                var mc:Object = event.target

                // TheBeetle is actually a MovieClip but i cannot write: var mc:MovieClip = event.target, if i do i receive 1118

               

               

                    if (mc.currentFrame == 1)

                    {

                        mc.gotoAndStop (Math.floor(Math.random() * 3 + 4));

                    }

                    else

                    {

                        mc.gotoAndStop (3);

                    }

                    mc.filters = null;

                    // Here i need to index the TheBeetle as i did before like gamelevel.setChildIndex(mc,1) but i'd receive 1118!

                    bArray.splice (bArray.indexOf(mc),1);

                    if (bArray.length == 0)

                    {

                        removeEventListener (Event.ENTER_FRAME,frameHandler);

                        waveTimer.removeEventListener (TimerEvent.TIMER_COMPLETE, changeLocation);

                    }

            }

        }

TOPICS
ActionScript
949
Translate
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

correct answers 1 Correct answer

Community Expert , Apr 02, 2014 Apr 02, 2014

cast it:

var mc:MovieClip=MovieClip(event.target);

Translate
Community Expert ,
Apr 02, 2014 Apr 02, 2014

cast it:

var mc:MovieClip=MovieClip(event.target);

Translate
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
Explorer ,
Apr 02, 2014 Apr 02, 2014

I LITERALLY CANNOT LIVE WITHOUT YOU:D U R A LIVING ANSWERING MACHINE

for (var i:int = 0; i <= stars; i++)

{

    THANKS MAN

}

Translate
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
Explorer ,
Apr 02, 2014 Apr 02, 2014

and can u explain why should i define it as a movieclip while it already is? thx

Translate
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 Expert ,
Apr 02, 2014 Apr 02, 2014
LATEST

you're welcome.

and you're correct.  it's not clear why flash should have to be told your event.target is a movieclip, but it does.

flash easily loses track of object types.  the simplest example is using 'root'.  under no circumstance (that i've found) can flash remember that 'root' is a movieclip.  (it can be a sprite if you create a document class that extends sprite, but otherwise it's a movieclip.)

anyway, i assume it would make flash slower and use more memory if it were to keep track of object types so that might be a reason why flash frequently needs help remembering.  but i don't really know if that's true.

Translate
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