I would like to embed a css file using
[Embed(source = 'mystyle.css', mimeType = 'text/css')]
private var _css:Class;
but 'text/css' is not a supported transcoder. Is there a list of transcoders that someone can point me to?
I really just need it to read plain text but 'text/pla开发者_如何学Cin' is not available either. Any other way of tricking as3 to do something really simple is appreciated.
As far as I'm aware, the MIME types supported in AS3/Flash are the same as those supported in Flex. Flex supports:
- application/octet-stream
- application/x-font
- application/x-font-truetype
- application/x-shockwave-flash
- audio/mpeg
- image/gif
- image/jpeg
- image/png
- image/svg
- image/svg-xml
Further information can be found here.
Anything that isn't specifically supported through these mime types should use "application/octet-stream". The file is embedded as a ByteArray object so you'll need to figure out how to parse it yourself, though CSS as plain text will be pretty straight forward. Depending on what CSS properties you're using you could even use the parseCSS function of the StyleSheet class.
You could also use MXML:
<fx:String id="myText" source="./examples/myText.txt"/>
Unfortunately, the "source" property does not show up in auto complete so people don't realize this property is available. Just type it out anyway and I think you'll be pleasantly surprised. Wink.
BUT be aware, if you use an open curly brace and closing curly brace the compiler may complain since it will try to interpret it as a databinding expression. You will need to escape the curly brace with a sodius, "\". So change any occurances of {
to \{
.
Also, here's more information on how to get the data from your embed.
Declare it like this:
[Embed(source="mystyle.css", mimeType="application/octet-stream")]
private var MyCSS:Class;
Get the value like this:
var myCSS:String = new MyCSS();
[Embed (souruce="vigsquare.pat", mimeType="application/octet-stream")] private var maker:Class;
[Embed (souruce="camera_para.dat", mimeType="application/octet-stream")] private var cam_params:Class;
transcoding parameter souruce is not supported by flex2.compiler.media.DataTranscoder
How to clear my error
精彩评论