View Full Version : [as3] How to use flex/as3 examples in flash 9
superjohn
February 10th, 2007, 04:59 PM
I want to test some things in AS3, and am currently trying to use some things i found on the internet. A lot of the examples are made for flex (i think).. they just dont work.
Take for example the pngencoder (http://labs.adobe.com/svn/flashplatform/?/projects/corelib/trunk/src/actionscript3/com/adobe/images/PNGEncoder.as)from adobe. Copy pasting it obviously doesnt work, so could anyone explain how to change it?..
Cant wait to try out all these examples :azn:
Dazzer
February 10th, 2007, 08:59 PM
actually I don't see any reason why it won't work.
all you got to do is save that pngencoder into a folder.
to save you trouble, put it in the same folder as your fla.
now you just have to import it
import com.adobe.images.PNGEncoder
put that at the beginning of your fla, or to get into the feel of AS3, use a document class instead.
then from what I see, just call
var temp:BitmapData = myDisplayObject.draw();
var bytes:ByteArray = PNGEncoder.encode(temp);
and voila you got your png.
taurianthebull
February 26th, 2008, 06:28 AM
Hey Hi,
I tried the same thing on my project, but failed. Here is what i did:
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import com.adobe.images.PNGEncoder;
var temp:BitmapData = myDisplayObject.draw();
var bytes:ByteArray = PNGEncoder.encode(temp);
I just simply want to be able to export PNG or JPG realtime from flash player. I have made a movieclip that contains some graphics and give it an instace name of "myBitmapData". But it gives me this error:
TypeError: Error #1006: draw is not a function.
at JPG_Export_test_fla::MainTimeline/JPG_Export_test_fla::frame1()
I am stuck here, any help with this?
Regards,
Aamir
Jerryscript
February 26th, 2008, 12:25 PM
BitmapData is a BitmapData object, not a movie clip named BitmapData.
You need to create a new BitmapData object, and draw the contents of a Sprite/MovieClip/Bitmap to it. Then you can encode the BitmapData using the PNGEncoder.
Check your documentation under flash.display.bitmapdata
dail
February 26th, 2008, 01:51 PM
Try this approach,
targetClip = someInstance
bitmapData = new BitmapData(targetClip.width, targetClip.height, true, 0xFFFFFF);
drawingRectangle = new Rectangle(0, 0, targetClip.width, targetClip.height);
bitmapData.draw(targetClip, new Matrix(), null, null, drawingRectangle, false);
var byteArray:ByteArray = new JPGEncoder().encode(bitmapData);
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.