Excellent tip!

Well, here's what I'm trying to do.  I have logos for various companies
embedded in my SWF.  I also have various graphs where the logos will be
shown in the datatip popup.  The contents of this datatip are returned in an
SQL statement.  Why SQL?  Because this is an easy place my boss can change
the stuff so he can play with different wordings and layouts without having
me compile the Flex app every time.

So he might change the query to:

select tip = 'Results for <logo>' from ...
or
select tip = company_name + '<br><logo><br>$' + convert(varchar, sales)

That's not exactly it, but you get the drift.  I want to be able to replace
<logo> with the appropriate logo for the company for the point on the
graph.  It may appear anywhere in the tip text.  He could also put whatever
html markup he wanted in the tip text.

Seems to me the easiest and most flexible way would be to use a TextArea or
similiar and set the htmlText property.  But of course I need to fill in
<logo> with whatever the correct logo image is.  I want these images to be
embedded in the SWF, so I can't just use "<img src='http://server/logo.png'>",
etc.

So what I have done is replace <logo> with <img id='logo' src=''>.  So an
example would be:

Footronics<br><img id='logo'><br>$123456

I might even go back and take out that step and just have the boss put in
"<img id='logo' src=''>" in the first place.  That way he can control
height/width if he wants to.

Right now, I've got only as far as using a TextArea to try to work out how
to do this.  If I assign the above to htmlText, I get an ioerror.  So I set
up a handler to cloak that.  And using your tip, I find that I can
successfully do this:

var ba:ByteArrayAsset = ByteArrayAsset(new logo);

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);
  }
}

Wonderful!

Well, sort of.  As I said, what I'd really like to use is SVGs.  This method
doesn't work very well with them, I'm sure due to the same problem that
forces you to only be able to use SVGs when they are embedded.  If you try
to use an SVG, you just get a continuous stream in the console log of

[SWF] C:\Documents and Settings\....\My Documents\Flex Builder
3\...\bin-debug\.....swf - 0 bytes after decompression

Over and over again.  Bother.  I suspect that may sink the whole
ByteArrayAsset approach.  Because I suspect I will have to embed the SVG,
then later create an object that will get make a bitmap version, THEN have
the Loader object load the bytes from it.  Somehow.  If it's even possible.

Unless someone else has a suggestion for a better way to let my boss be able
to type in all this formatted html with embedded logos that are in SVG
format.


On Wed, Sep 17, 2008 at 5:13 PM, Jim Hayes <[EMAIL PROTECTED]> wrote:

>
> 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: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com> [mailto:
> flexcoders@yahoogroups.com <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

Reply via email to