Accessing JpegEncoder class from JavaScript in Adobe AIR application
I need to encode a BitmapData object using the JPegEncoder in a Adobe AIR application using JavaScript
I am trying to create a JpegEncoder object
var encoder=new window.runtime.mx.graphics.codec.JPEGEncoder()
and I get the error
TypeError: Result of expression 'window.runtime.mx.graphics.codec.JPEGEncoder' [] is not a constructor.
I am not sure if I done something wrong or it is not possible to access that class This is my mxml header
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
Update: I found that you need to add a reference to the swf/swc ,here is a smaple code for an application that us开发者_如何学Pythones rpc
<script type="application/x-shockwave-flash"
src="lib/air/swf/framework/framework/library.swf"></script>
<script type="application/x-shockwave-flash"
src="lib/air/swf/framework/rpc/library.swf"></script>
I tried adding mx instead of rpc but it does not work, I am thinking if i need to deploy the mx.swc file with the application?(i think it should not be needed) or maybe it can't resolve that path
I solved it by deploying the framework.swf file wioth the application but can it be done without it?Is this file present on the client machines?
Not sure why the 'window.runtime'...
using xmlns:mx="http://www.adobe.com/2006/mxml"
and explicitly importing the class works fine for me...
And you would also get a compiler warning about not specifying a type for the variable, ie you want:
import mx.graphics.codec.JPEGEncoder;
var encoder:JPEGEncoder = new JPEGEncoder();
And please - I have seen far to much AS code that relies on not requiring a semi-colon to terminate a statement - use them - the FB ide is much nicer if you do (auto-correct indenting etc), not to mention this often leads to mixed 'usage' with some lines using it other not - I wish adobe would remove this 'feature'
精彩评论