Once a month this issue comes up.  Because there is no function
olverloading in AS3, we can't change the parameter list of addChild, but
basically, frameworks have rules and the rules for Flex are:

 

Navigator children must be Containers

Container children must be IUIComponents

UIComponent children can be anything.

 

I swear I replied to this thread two days ago, but answer is to
instantiate a UIComponent and addChild your sprite to it.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Blake Barrett
Sent: Wednesday, March 05, 2008 12:48 PM
To: [email protected]
Subject: RE: [flexcoders] Re: How can I add Sprite / MovieClip to stage
without error of not IUIComponent?

 

I've been experiencing similar issues from a slightly different
direction. I have various things in a swf file authored in Flash CS3 and
I have been needing to pull them out of that swf and add them to the
stage in a Flex 2.0.1 app. What I ended up having to do is actually
create an instance of an <mx:SWFLoader/> in the MXML and address
everything through that. I was met with mixed results trying to
dynamically add a new SWFLoader(), but I was able to do what I needed to
do using the <mx:SWFLoader/> (since it is some sort of Flex object that
loads an AVM2Movie SWF as its .content property once it is done
loading).

 

It's kinda ghetto, but maybe you could look into the <mx:Sprite/>
object. Maybe create one of those declaratively, give it an ID and just
manipulate that.

 

Blake

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of m88e24
Sent: Wednesday, March 05, 2008 8:11 AM
To: [email protected]
Subject: [flexcoders] Re: How can I add Sprite / MovieClip to stage
without error of not IUIComponent?

Regarding Flex 3, addChild with a Sprite instance as argument does not
work in contrast to what the Flex 3 documentation tells us. One of the
examples taken from the Flex 3 language reference:

public function SpriteExample() {
var child:Sprite = new Sprite();
child.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler);
child.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
draw(child);
addChild(child);
}

The method signature is public function
addChild(child:DisplayObject):DisplayObject 

Clearly the addChild should accept any instance of DisplayObject which
Sprite clearly is. It worries me deeply that a type cast is performed
in the private override mx_internal function
addingChild(child:DisplayObject):void

// Throw an RTE if child is not an IUIComponent.
var uiChild:IUIComponent = IUIComponent(child);

It worries me even more that this slipped through QA. Adobe please
explain why this is.

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Brian" <[EMAIL PROTECTED]> wrote:
>
> I tried that - same problem. In Container.addChild(DisplayObject), the
> first thing it does is check to see if the object passed in is an
> IUIComponent.
> 
> I just realized I'm still using Flex2. Did this change in Flex 3? Is
> that the problem?
> 
> --- In [email protected]
<mailto:flexcoders%40yahoogroups.com> , Sherif Abdou <sherif626@> wrote:
> >
> > try adding it to a FlexSprite then to a UIComponenet or any of those
> FlexDisplayObject classes
> > 
> > 
> > 
> > ----- Original Message ----
> > From: Brian <briforge@>
> > To: [email protected] <mailto:flexcoders%40yahoogroups.com>

> > Sent: Saturday, March 1, 2008 5:32:13 PM
> > Subject: [flexcoders] Re: How can I add Sprite / MovieClip to stage
> without error of not UIComponent
> > 
> > I'm echoing the request for an example here because I'm having the
> > exact same problem. How would you 'add everything meaningfull stuff
as
> > child of that UIComponent' , when UIComponent. addChild( ) has the
same
> > restrictions as the original component I tried adding the
MovieClip to?
> > 
> > I also tried adding a MovieClip to a TitleWindow for a popUp instead
> > of the stage and had the same error.
> > 
> > --- In [EMAIL PROTECTED] ups.com, "helihobby" <helihobby@ ..>
wrote:
> > >
> > > Can you post an example please ?
> > > 
> > > --- In [EMAIL PROTECTED] ups.com, Jonathan Lee <jlee_lee740304@
>
> > > wrote:
> > > >
> > > > What I did is just add a UIComponent under the container as a
child.
> > > The add everything meaningful stuff as child of that UIComponent.
> > > > 
> > > > 
> > > > 
> > > > helihobby <helihobby@> wrote: This
> > > is the exact error I get:
> > > > 
> > > > Main Thread (Suspended: TypeError: Error #1034: Type Coercion
> failed:
> > > > cannot convert flash.display: :MovieClip@ 479b1f1 to
> > > mx.core.IUIComponen t.) 
> > > > 
> > >
> > mx.core::Container/http://www.adobe. com/2006/ flex/mx/internal
> ::addingChild
> > > > 
> > > > mx.core::Container/ addChildAt 
> > > > mx.core::Container/ addChild 
> > > > TestAS12344/ setFire 
> > > > TestAS12344/ onClick 
> > > > TestAS12344/ __bb_click 
> > > > 
> > > > --- In [EMAIL PROTECTED] ups.com, "helihobby" <helihobby@>
wrote:
> > > > >
> > > > > 
> > > > > How can I add Sprite / MovieClip to stage without error of not
> > > > > UIComponent ?
> > > > > 
> > > > > Everytine I add a Sprite or MC I get the error ... even if I
> try to
> > > > > cast to a DisplayObject ...
> > > > > 
> > > > > Any help is greatly appreciated ...
> > > > > 
> > > > > Sean.
> > > > >
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > ------------ --------- --------- ---
> > > > Looking for last minute shopping deals? Find them fast with
Yahoo!
> > > Search.
> > > >
> > >
> > 
> > 
> > 
> > 
> > 
> > 
>
__________________________________________________________
> > Looking for last minute shopping deals? 
> > Find them fast with Yahoo! Search. 
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
<http://tools.search.yahoo.com/newsearch/category.php?category=shopping>

> >
>

 

Reply via email to