Access JavaScript JpegEncoder class in Adobe AIR application

I need to encode a BitmapData object using JPegEncoder in an 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 an error

TypeError: the result of the expression 'window.runtime.mx.graphics.codec.JPEGEncoder' [] is not a constructor.

I'm not sure if I did something wrong or it is not possible to access this 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 link to swf / swc, here is the smaple code for an application that uses 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 think if I need to deploy the mx.swc file with the application? (I think this is not necessary) or perhaps he cannot solve this problem the way

I solved this by deploying the framework.swf file using the application, but can this be done without it? Is this file present on client machines?

+4
source share
1 answer

I don’t know why "window.runtime" ...

using xmlns:mx="http://www.adobe.com/2006/mxml" and explicitly importing the class works fine for me ...
And you will also get a compiler warning not to indicate the type for the variable, i.e. you want:

 import mx.graphics.codec.JPEGEncoder; var encoder:JPEGEncoder = new JPEGEncoder(); 

And please, I have not seen so much AS code that relied on something that did not require a semicolon to complete the statement - use them. The idea of ​​FB is much nicer if you do this (auto-correction of indentation, etc.), and not mentioning it often leads to mixed "use" with some lines that use it by others - I do not want adobe to remove this "function"

0
source

All Articles