0

I create my symbol with a class name

enter image description here

I publish as an SWC, and in flash buildr it looks like this

enter image description here enter image description here

I import MyRect and try and use it

var redRect:MyRect = new MyRect;
     addChild(redRect);

I get an error

Implicit coercion of a value of type MyRect to an unrelated type DisplayObject....line 93 Flex Problem

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • You can not add MovieClip (or Sprite) classes directly to most Flex components - try adding MyRect to a UIComponent instead. –  Apr 22 '13 at 15:37
  • it is an actionscript project – LeBlaireau Apr 22 '13 at 15:52
  • why do you have "Flex" in your error message then? –  Apr 22 '13 at 15:55
  • see latest screen was at the end in the 'type' box. But this is setup on FB 4.7 as an Actionscript project running on air. – LeBlaireau Apr 22 '13 at 16:01
  • When you open up your swc in the "Referenced Libraries" part of the Project Explorer, do you see a MyRect.abc Class listed there? – Amy Blankenship Apr 22 '13 at 17:42
  • Your subject line is a bit confusing. Is it safe to assume you are exporting using Flash Professional CS6? I tried modifying the subject line to be more clear. Are you seeing a compile time error or a runtime error? – JeffryHouser Apr 22 '13 at 21:01

1 Answers1

0

I think the problem is in how your declaring it. It might have to do with the object type. Try this:

var objects:Array;
objects = [0];
objects[0] = new MyRect();
addChild(objects[0]);

and see what happens.

  • Why would putting the component in an Array affect this? – JeffryHouser Apr 22 '13 at 20:59
  • I think Ronnie is trying to get around the typing error by using an essentialy untyped variable. – Amy Blankenship Apr 22 '13 at 21:13
  • Which would remove the compile-time error, but the runtime-error would still exist. To Ronnie: You could get around this simply by doing `addChild( new Rect() as * )` instead of what you did. Regardless, this will only help compiler errors and will crash the app when it hits that line. – Josh Apr 22 '13 at 22:04