Skip to main content
Participant
June 1, 2015
Answered

Why does button in movieclip produce Error #1034

  • June 1, 2015
  • 5 replies
  • 456 views

I have a sliding menu with multiple movieclips.  I want to add buttons to each panel to link to PDFs.  The button works, but the code produces the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@114e2941 to flash.display.MovieClip.

  at slideshow_fla::MainTimeline/onClick()

I tried to bypass the panel tweening portion by checking for child type, but it doesn't seem to ignore the button.  What am I missing?

import gs.*;

import gs.easing.*;

s1.props = {lx:0, rx:350, ind:1};

s2.props = {lx:36.45, rx:386.45, ind:2};

s3.props = {lx:72.90, rx:422.95, ind:3};

s4.props = {lx:109.40, rx:459.45, ind:4};

s5.props = {lx:145.85, rx:495.90, ind:5};

s6.props = {lx:182.35, rx:532.40, ind:6};

s7.props = {lx:218.80, rx:568.85, ind:7};

s8.props = {lx:255.25, rx:605.30, ind:8};

s9.props = {lx:291.75, rx:641.80, ind:9};

s10.props = {lx:328.20, rx:678.25, ind:10};

s11.props = {lx:364.70, rx:714.45, ind:11};

s12.props = {lx:401.15, rx:751.20, ind:12};

s13.props = {lx:437.60, rx:787.65, ind:13};

s14.props = {lx:474.10, rx:824.15, ind:14};

s15.props = {lx:510.55, rx:860.60, ind:15};

s16.props = {lx:547.05, rx:897.10, ind:16};

s17.props = {lx:583.50, rx:933.55, ind:17};

s1.addEventListener(MouseEvent.CLICK, onClick);

s2.addEventListener(MouseEvent.CLICK, onClick);

s3.addEventListener(MouseEvent.CLICK, onClick);

s4.addEventListener(MouseEvent.CLICK, onClick);

s5.addEventListener(MouseEvent.CLICK, onClick);

s6.addEventListener(MouseEvent.CLICK, onClick);

s7.addEventListener(MouseEvent.CLICK, onClick);

s8.addEventListener(MouseEvent.CLICK, onClick);

s9.addEventListener(MouseEvent.CLICK, onClick);

s10.addEventListener(MouseEvent.CLICK, onClick);

s11.addEventListener(MouseEvent.CLICK, onClick);

s12.addEventListener(MouseEvent.CLICK, onClick);

s13.addEventListener(MouseEvent.CLICK, onClick);

s14.addEventListener(MouseEvent.CLICK, onClick);

s15.addEventListener(MouseEvent.CLICK, onClick);

s16.addEventListener(MouseEvent.CLICK, onClick);

s17.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void

{

  var clicked:MovieClip = MovieClip(e.target);

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

  {

  if(getChildAt(i) is MovieClip){

  var mc:MovieClip = MovieClip(getChildAt(i));

  if(mc.props.ind <= clicked.props.ind)

  TweenLite.to(mc, 1, {x:mc.props.lx, ease:Expo.easeOut});

  else

  TweenLite.to(mc, 1, {x:mc.props.rx, ease:Expo.easeOut});

  }

  }

}

s1.b1.addEventListener(MouseEvent.CLICK, onBtn1Press);

function onBtn1Press(e:MouseEvent)

{

  trace("Button 1 pressed");

}

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

you should enable debugging so you can see the line of code causing the problem, but from looking at your code, this looks like the problem:

  var clicked:MovieClip = MovieClip(e.target);

fix it

5 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 1, 2015

you should enable debugging so you can see the line of code causing the problem, but from looking at your code, this looks like the problem:

  var clicked:MovieClip = MovieClip(e.target);

fix it

Participant
June 1, 2015

Hello, thank you for your suggestion, and your assumption of the offending line is correct.  I found that my check for the object type (MC or Button) was after the offending line.  I rearranged the code so that the check is before it, but after the "i" variable is set as in the following.  However, it still does not bypass the animation loop when the button is clicked.

function onClick(e:MouseEvent):void

{

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

  if(getChildAt(i) is MovieClip){           //If this is a button click, skip this animation loop

  var clicked:MovieClip = MovieClip(e.target);

  {

  var mc:MovieClip = MovieClip(getChildAt(i));

  if(mc.props.ind <= clicked.props.ind)

  TweenLite.to(mc, 1, {x:mc.props.lx, ease:Expo.easeOut});

  else

  TweenLite.to(mc, 1, {x:mc.props.rx, ease:Expo.easeOut});

  }

  }

}

kglad
Community Expert
Community Expert
June 1, 2015

do yourself a favor and add curly brackets:

function onClick(e:MouseEvent):void{

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

  if(getChildAt(i) is MovieClip){           //If this is a button click, skip this animation loop

  var clicked:MovieClip = MovieClip(e.target);

  var mc:MovieClip = MovieClip(getChildAt(i));

  if(mc.props.ind <= clicked.props.ind){

  TweenLite.to(mc, 1, {x:mc.props.lx, ease:Expo.easeOut});

  } else {

  TweenLite.to(mc, 1, {x:mc.props.rx, ease:Expo.easeOut});

  }

  }

}

}

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)