Thanks Gordon,

That worked.  One other question regarding Sprite Drag and Drop.

Situation:  Have a box drawn by the Shape Class which is in a Sprite.   
            I have the following code:

-------- Draw Rectangle ------------------------------------------

    private function draw (name:String) {

      if (w > 0 && h > 0) {

                var sprite:Sprite = new Sprite();
                sprite.name = name;
                trace("name= " + name);
                addChild(sprite);
 
        var child:Shape = new Shape();
        child.graphics.beginFill(0xffffff);
        child.graphics.lineStyle(.5, 0x000000);
        child.graphics.drawRect(0, 0, w, h);
        child.graphics.endFill();
        sprite.addChild(child);
       
        sprite.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
      }
     
    }

----------- dragObject -----------------------------------------------

        private function dragObject(event:MouseEvent)
        {
                 
                if (event.target.name == "obj"){
                        
            var
dragInitiator:UIComponent=UIComponent(event.currentTarget);
            var ds:DragSource = new DragSource();

            ds.addData("name","format");

            var canvasProxy:Sprite = new Sprite();
            canvasProxy.width=30;
            canvasProxy.height=30;

            DragManager.doDrag(dragInitiator, ds, event);

                }
        }

----------------------------------------------------------------
When I try to drag this object, I get the following Error:

Type Coercion failed: cannot convert flash.display::[EMAIL PROTECTED] to
mx.core.UIComponent

If I don't cast the sprite to the UIComponent, I still get the same
error.  It seems that the DragManager likes UIComponent types.

What would be a solution do you think.

Cheers,

Tim






--- In flexcoders@yahoogroups.com, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> Make ImageViewer extend UIComponent instead of Sprite. In order to do
> stuff like automatic layout, Flex containers expect their content
> children to be UIComponents.
> 
> - Gordon
> 
> 
> -----Original Message-----
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of sufibaba
> Sent: Thursday, March 02, 2006 11:11 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] visual children must implement
> mx.core.IUIComponent
> 
> Hi All,
> 
> I have the following:
> 
> 1. ImageViewer.as
> 2. main.xml
> 
> in ImageViewer.as, I have this class definition:
> 
> public class ImageViewer extends Sprite {
>    public funtion ImageViewer(){
>     // code
>    }
>   // other functions and code
> }
> 
> 
> in main.xml, I am calling:  <ImageViewer/>
> 
> The error I am getting is:
> ---------------------------------------------------------------------
> component declaration are now allowed in here.(Note: visual children
> must implement mx.core.IUIComponent)
> ---------------------------------------------------------------------
> Does anone know what the problem might be.
> 
> Any help is appreciated,
> 
> Cheers,
> 
> Tim
> 
> 
> 
> 
> 
> 
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com 
> Yahoo! Groups Links
>





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to