Skip to main content
Participating Frequently
Aug 13, 2024 11:21 PM UTC
Question

import

Hello everyone
I'm having a problem with my Action, when I try to import (import com.adobe.images.PNGEncoder) nothing appears in the menu, it's empty and then the error appears as shown in the attached image, can someone please help me, what could be happening??
Thank you very much.

 

This topic is closed to new replies. Start a new post to keep the conversation going.

14 replies

JoãoCésar17023019
Community Expert
Community Expert
Aug 14, 2024 9:37 PM UTC

Hi.

 

Use the BitmapData's encode method and the PNGEncoderOptions class. Like this:

import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.PNGEncoderOptions;
import flash.geom.Rectangle;
import flash.net.FileReference;
import flash.utils.ByteArray;

function snapshot(target:DisplayObject, fileName:String):void
{
	var bitmapData:BitmapData = new BitmapData(target.width, target.height);
	var byteArray:ByteArray = new ByteArray();
	var fileReference:FileReference;
	
	bitmapData.draw(target);
	bitmapData.encode(new Rectangle(0, 0, bitmapData.width, bitmapData.height), new PNGEncoderOptions(), byteArray);
	fileReference = new FileReference();
	fileReference.save(byteArray, fileName);
}

snapshot(yourContainer, "capture_" + new Date().time + ".png");


Regards,
JC

Translate
Participating Frequently
Aug 15, 2024 1:55 AM UTC

Vou tentar isso tambem, apesar que deu certo, apenas quando salvo o arquivo e quando tento abrir, ele diz que "Não tem suporte para este tipo de aquivo", será que ainda é algum tipo de problema com o Flash ??

 

Translate
JoãoCésar17023019
Community Expert
Community Expert
Aug 15, 2024 12:16 PM UTC

The code exports a .png but it seems you're opening a .jpg.

 

Make sure the extension is correct.

Translate
kglad
Community Expert
Community Expert
Aug 13, 2024 11:41 PM UTC

that package is incorrect.  check the as3 api

Translate
Participating Frequently
Aug 14, 2024 12:13 AM UTC

Hello friend kosglad
Thank you for your help, I apologize but I have no idea how to solve this problem, I don't even know where to start, where to move, this has never happened to me before.

Translate
kglad
Community Expert
Community Expert
Aug 14, 2024 12:25 AM UTC

https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html

 

check the pngencoder package 

 

mx.graphics.codec.PNGEncoder

Translate