No, the issue is exactly what I described: objects that implement
IUIComponent (which Canvas does, TextField does not) add a restriction to
the inherited (from DisplayObjectContainer) addChild methods. The
restriction is that the child *actually* has to implement IUIComponent. This
is so the component can call the "measuredHeight", etc., methods to preform
layout (whereas a standard DisplayObjectContainer doesn't perform layout and
thus doesn't need the additional properties).

What Grant Skinner's blog post describes is really just a *slightly* more
verbose version of what Ely posted (with several examples of how to use it
in both MXML and AS). It also has the nice upside that if your DisplayObject
resizes it can automatically resize the UIComponent.

So, go over to Grant's blog and check out the post. It'll clear everything
up.

The trick with hijacking an image is interesting, but really unnecessary.
Grant's solution is only about two dozen lines of code (with comments) and
works like a charm (you may need to add one or two checks for nulls for
safety's sake depending on your use case, otherwise it seems production
ready to me).

And the cloning... well, I've got no idea how that would make a difference!
;-)

Troy.


On 3/21/07, tosadavemgr <[EMAIL PROTECTED]> wrote:

  It is interesting that I would get 4 replies, 4 completely different
answers. My entire week is going this way. As is my Flex project.
So my choices were:

1. Try the Grant Skinner blog and his DisplayObjectWrapper. Not
exactly sure how this works or how to use it within my code.
2. Add .clone to my existing syntax, which I tried without luck
3. Have an image load an image and then copy that - interesting, yet I
have a canvas loaded with many bitmaps and need to make a bitmap of
the canvas ??
4. And finally, from Ely, and extension of the UIComponent class. I'm
sure this is something, but I'm not sure how to use it.

I really appreciate the helpful spirit on this message board. My own
green-ness with Flex is part of the problem, but I thought for sure my
original direction would work since I pulled it almost directly from
the Flex docs.

Here's the code from Flex Docs:

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;

var tf:TextField = new TextField();
tf.text = "bitmap text";

var myBitmapData:BitmapData = new BitmapData(80, 20);
myBitmapData.draw(tf);
var bmp:Bitmap = new Bitmap(myBitmapData);
this.addChild(bmp);

They are copying a TextField rather than a canvas. Is that the issue?
OK to turn a TextField into a bitmap, but not a canvas?

Dave


--- In [email protected] <flexcoders%40yahoogroups.com>, "Ely
Greenfield" <[EMAIL PROTECTED]> wrote:
>
>
>
>
> [DefaultProperty("content")]
> class RawContainer extends UIComponent
> {
> private var _content:Array = [];
> public function set content(value:Array):void
> {
> _content = value;
> for(var i:int = 0;i<_content.length;i++)
> {
> addChildAt(_content[i],i);
> }
> while(numChildren > _content.length)
> removeChildAt(_content.length);
> }
> public function get content():Array { return _content }
> }
>
> Ely.
>
>
> ________________________________
>
> From: [email protected] <flexcoders%40yahoogroups.com> [mailto:
[email protected] <flexcoders%40yahoogroups.com>] On
> Behalf Of Troy Gilbert
> Sent: Wednesday, March 21, 2007 9:42 AM
> To: [email protected] <flexcoders%40yahoogroups.com>
> Subject: Re: [flexcoders] copying bitmap data
>
>
>
> Yeah, the problem is that the Canvas container only allows children that
> implement IUIComponent. It would have been real nice if Adobe had
> provided a "raw" container that did no layout of its children (but
> implemented IUIComponent itself), but they didn't.
>
> Fortunately, Grant Skinner has provided just such a container...
> DisplayObjectWrapper. Check out his blog or Google for it.
>
> If you wrap your Bitmap with the DisplayObjectWrapper first you'll then
> be able to add it (or rather, the DisplayObjectWrapper) to the canvas.
>
> Troy.
>
>
>
> On 21 Mar 2007 08:18:46 -0700, tosadavemgr <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> > wrote:
>
> I have a canvas in my layout and the application allows dragging
> and
> dropping items into the canvas. I need to be able to grab a
> bitmap of
> the canvas when the user is finished, so I can display the
> drawing on
> another panel, and in the FlexPrintJob function.
>
> I've tried using this code, initiated from a button:
>
> private function myDrawing():void{
> var myBitmapData:BitmapData = new BitmapData(530, 445);
> myBitmapData.draw(myWorkspace1);
> var bmp:Bitmap = new Bitmap(myBitmapData);
> showDrawing.addChild(bmp); //this isn't working
>
> }
>
> myWorkspace1 is the ID of the canvas where everything is
> dropped.
> I have a canvas with the ID=showDrawing that I'd like the bitmap
> to
> appear in.
> Anyone know what I need to add to the above function to get that
> done?
>
> Dave
>

Reply via email to