Skip to main content
Inspiring
April 2, 2014
Answered

Why am I getting error 1118 here?

  • April 2, 2014
  • 1 reply
  • 987 views

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);

                    }

            }

        }

This topic has been closed for replies.
Correct answer kglad

cast it:

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

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 2, 2014

cast it:

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

Inspiring
April 2, 2014

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

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

{

    THANKS MAN

}