Skip to main content
Participating Frequently
August 13, 2024
Question

import

  • August 13, 2024
  • 2 replies
  • 967 views

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 has been closed for replies.

2 replies

JoãoCésar17023019
Community Expert
Community Expert
August 14, 2024

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

Participating Frequently
August 15, 2024

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 ??

 

JoãoCésar17023019
Community Expert
Community Expert
August 15, 2024

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

 

Make sure the extension is correct.

kglad
Community Expert
Community Expert
August 13, 2024

that package is incorrect.  check the as3 api

Participating Frequently
August 14, 2024

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.

kglad
Community Expert
Community Expert
August 14, 2024

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

 

check the pngencoder package 

 

mx.graphics.codec.PNGEncoder