Well, for one thing, the program is a bit up in the air on final
specifications.  Sometimes it's running off the network, other times it's
running locally.  It's just very handy to move around one single SWF and not
have to drag along all the various logos.  It's also handy for the SWF to
have a builtin list of possible logos to use.  I admit that part of the
reason is just to see if I could, and therefore to add to the toolbox of
abilities I have.

And I'm pleased to announce that I have succeeded!

There might be a better way to do it, but what I'm doing now is this:

        var svg:DisplayObject = new logo;
        var bd:BitmapData = new BitmapData(svg.width, svg.height);
        bd.draw(svg);
        var ba:ByteArray = new PNGEncoder().encode(bd);

        for (var i:int = 0; i < testtext.numChildren; i++)
        {
          var o:DisplayObject = testtext.getChildAt(i);
          if (o is UITextField)
          {
            var r:Loader = UITextField(o).getImageReference("logo") as
Loader;
            r.loadBytes(ba);
          }
        }

There's the minor issue of resizing the svg before converting it to a
bitmap.  But I've made some progress on doing that.  And I'll probably
subclass Text or some component so I can get at textField without having to
iterate through the children.

Thanks to everyone for their help, and I look forward to hearing any further
suggestions, tips or mockery.  ;)

I'll try to write up a more complete example for posterity and post it as a
followup.


On Wed, Sep 17, 2008 at 10:48 PM, Alex Harui <[EMAIL PROTECTED]> wrote:

>    I was just thinking that if you didn't specify mimeType, it would give
> you a Bitmap subclass and you wouldn't need to loadbytes it.
>
>
>
> But it looks to me that your main issue is trying to get embedded images
> into a TextField's htmlText, and I can't think of any way to pull that off.
> If you know it is just going to be simple html and an icon, you might just
> parse the html and generate instances of widgets.  See the HTML and Flex
> post on my blog
>
>
>
> But easiest would be to not embed the logos and let the TextField load
> them.  I'm not sure why you want to embed the logos.  Depending on their
> size and quantity and what percentage of them get actually used, it might be
> better to get them over http.  After the first fetch it should be in their
> browser cache.
>
>
>
> -Alex
>
>
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *Pan Troglodytes
> *Sent:* Wednesday, September 17, 2008 6:25 PM
> *To:* [email protected]
> *Subject:* Re: [flexcoders] possible to get bytes from a pre-existing
> Image?
>
>
>
> Alex - did part of your reply get chopped off?  I'm not quite
> understanding.
>
> On Wed, Sep 17, 2008 at 6:51 PM, Alex Harui <[EMAIL PROTECTED]> wrote:
>
> It might be a subclass of Bitmap
>
>
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *Jim Hayes
> *Sent:* Wednesday, September 17, 2008 3:13 PM
> *To:* [email protected]
> *Subject:* RE: [flexcoders] possible to get bytes from a pre-existing
> Image?
>
>
>
>
> I as far as I can work out
>
> [Embed(source="logo.png", mimeType="application/octet-stream")] public var
> logo:Class;
>
> would enable you to access logo as a bytearray.
>
> I hope that helps? I'm still not really quite sure what you're trying to
> do, to be honest.
>
> Anyway, you might want to have a look at this :
>
> http://dispatchevent.org/roger/embed-almost-anything-in-your-swf/
>
> which I think might be at least along the lines of what you want to know,
> apologies in advance if I've got the wrong end of the stick.
>
> -----Original Message-----
> From: [email protected] <flexcoders%40yahoogroups.com> [mailto:
> [email protected] <flexcoders%40yahoogroups.com>] On Behalf Of
> Pan Troglodytes
> Sent: 17 September 2008 22:26
> To: flexcoders
> Subject: [flexcoders] possible to get bytes from a pre-existing Image?
>
> This question is really part of a larger ball of stuff I'm trying to
> untangle.  Basically, the first part is that if I have this:
>
> [Embed(source="logo.png")] public var logo:Class;
> ...
> var img:Image = new Image;
> img.source = logo;
>
> Is there any way to get a ByteArray from img that can be fed to Loader?
> Unfortunately, I'm stuck with Loader.  If you really want to know, I'm
> trying to mess with a TextArea that has htmlText with an <img> tag in it.  I
> want to switch the img tag to switch between different images that are
> embedded in the SWF. As far as I can tell, there's no way to tell an <img>
> tag to load an image out of the SWF.  Feel free to correct me on that.
> Because of some features of the environment, I really want to embed the
> images and not load them from the local file system or over the network.
>
> Eventually, I actually want to replace the PNG with an SVG.  This is part
> of why I'm wanting to have the files embedded.  But I know this will bring
> further challenges, as SVG is a vector format and I will have to get a
> raster rendering of the SVG at a certain size before I can ever expect to
> feed it to Loader.  But I'm trying to take it one giant hurdle at a time.
>
> Any thoughts, other than that I'm insane to do such a thing?
>
> --
> Jason
>
>
> __________________________________________________________
> This communication is from Primal Pictures Ltd., a company registered in
> England and Wales with registration No. 02622298 and registered office: 4th
> Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK.
> VAT registration No. 648874577.
>
> This e-mail is confidential and may be privileged. It may be read, copied
> and used only by the intended recipient. If you have received it in error,
> please contact the sender immediately by return e-mail or by telephoning
> +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its
> contents to any person.
> This email has been scanned for Primal Pictures by the MessageLabs Email
> Security System.
> __________________________________________________________
>
>
>
>
> --
> Jason
>
>   
>



-- 
Jason

Reply via email to