I am developing an Adobe Air app. I need to set an icon to the app so it is shown on the task bar. I added the icon tag to the descriptor file but it is not working and I really don't know why, any ideas?
How to set icon to an adobe air application
airapache-flexiconstaskbar
Related Solutions
Tracking it down
At first I thought this was a coercion bug where null
was getting coerced to "null"
and a test of "null" == null
was passing. It's not. I was close, but so very, very wrong. Sorry about that!
I've since done lots of fiddling on wonderfl.net and tracing through the code in mx.rpc.xml.*
. At line 1795 of XMLEncoder
(in the 3.5 source), in setValue
, all of the XMLEncoding boils down to
currentChild.appendChild(xmlSpecialCharsFilter(Object(value)));
which is essentially the same as:
currentChild.appendChild("null");
This code, according to my original fiddle, returns an empty XML element. But why?
Cause
According to commenter Justin Mclean on bug report FLEX-33664, the following is the culprit (see last two tests in my fiddle which verify this):
var thisIsNotNull:XML = <root>null</root>;
if(thisIsNotNull == null){
// always branches here, as (thisIsNotNull == null) strangely returns true
// despite the fact that thisIsNotNull is a valid instance of type XML
}
When currentChild.appendChild
is passed the string "null"
, it first converts it to a root XML element with text null
, and then tests that element against the null literal. This is a weak equality test, so either the XML containing null is coerced to the null type, or the null type is coerced to a root xml element containing the string "null", and the test passes where it arguably should fail. One fix might be to always use strict equality tests when checking XML (or anything, really) for "nullness."
Solution
The only reasonable workaround I can think of, short of fixing this bug in every damn version of ActionScript, is to test fields for "null" and escape them as CDATA values.CDATA values are the most appropriate way to mutate an entire text value that would otherwise cause encoding/decoding problems. Hex encoding, for instance, is meant for individual characters. CDATA values are preferred when you're escaping the entire text of an element. The biggest reason for this is that it maintains human readability.
There are actually two ways to add a favicon to a website.
<link rel="icon">
Simply add the following code to the <head>
element:
<link rel="icon" href="http://example.com/favicon.png">
PNG favicons are supported by most browsers, except IE <= 10. For backwards compatibility, you can use ICO favicons.
Note that you don't have to precede icon
in rel
attribute with shortcut
anymore. From MDN Link types:
The
shortcut
link type is often seen beforeicon
, but this link type is non-conforming, ignored and web authors must not use it anymore.
favicon.ico
in the root directory
From another SO answer (by @mercator):
All modern browsers (tested with Chrome 4, Firefox 3.5, IE8, Opera 10 and Safari 4) will always request a
favicon.ico
unless you've specified a shortcut icon via<link>
.
So all you have to do is to make the /favicon.ico
request to your website return your favicon. This option unfortunately doesn't allow you to use a PNG icon.
See also favicon.png vs favicon.ico - why should I use PNG instead of ICO?
Best Answer
Two things that might be throwing you off:
1) the icons block is commented out by default in the auto-generated descriptor file, and is an easy thing to overlook
2) the icons specified in a descriptor file don't appear in the app unless you build a release build, and install the resulting .air file. A debug build will only show the AIR icon.
At least these are the behaviors I experience in Flash Builder 4.