I am working on a prototype in which I'm adding a texture to movieClip.
Here is my code :
[Embed(source = "/../assets/demo_img.png")]
protected var asset01:Class;
[Embed(source="/../assets/demo_img.xml",mimeType="application/octet-stream")]
protected var data01:Class;
and my movieClip code is :
var myTexture:Texture = Texture.fromBitmap(new asset01());
var atlas:TextureAtlas = new TextureAtlas(myTexture, XML(new data01()));
var mc:MovieClip = new MovieClip(atlas.getTextures("demo_img_"), 10);
but it gives me error :
Error: exception during transcoding: Failed to grab pixels for image \..\PP143Starling\assets\demo_img.png
If anyone have any idea about it, please share.
I faced similar issue and the weird part was it started coming without any change in the code. Initially i faced an issue with windows memory and then eclipse memory and then this error surfaced:
exception during transcoding failed to grab pixels for image
Embed was also not recognized by compiler anymore.
The fix is very simple. I just cleaned my project in eclipse and the error was cleared.
Related
The Problem
When I was creating a test program using Flash Professional CC, I got the message "Test Movie Launch Failed" while compiling, and when I tried to open it, nothing happened and it didn't open. However, I got no compiler errors whatsoever, it just said "Test Movie Terminated." in the output.
What Might be Going on
I was thinking it might have been an error in my code, but I can't tell since the error message is extremely vague and no runtime errors appear.
So Here's my code (just in case if it's an error of the code)
Info:
Target: Air 3.6 for Desktop
Script: ActionScript 3.0
Objects:
Input Text Box with instance name of "writeT"
Dynamic Text Box with instance name of "readT"
MovieClip with instance name of "Write" (Too lazy to make buttons)
MovieClip with instance name of "Read"
import flash.filesystem.*;
import flash.events.MouseEvent;
Write.addEventListener(MouseEvent.CLICK, writeToFile);
Read.addEventListener(MouseEvent.CLICK, readFile);
var file:File = File.desktopDirectory.resolvePath("stuff.txt");
var fs:FileStream = new FileStream();
function writeToFile(e:MouseEvent):void{
fs.open(file, FileMode.APPEND);
var text:String = writeT.text;
fs.writeUTF(text);
writeT.text = "";
fs.close();
}
function readFile(e:MouseEvent):void{
fs.open(file, FileMode.READ);
var text:String = fs.readUTF();
readT.text = text;
fs.close();
}
EDIT: I commented all of my code and the error still showed up, so ignore the code
I typically see this if I use a library (.swc or .ane) that the desktop debugger cannot use.
If you using any libraries, perhaps uncouple them to see if the error disappears.
Difficult to say what the exact problem could be. From what I read, seems like a version issue. This thread maybe of some help : https://forums.adobe.com/thread/1007928
On a side note, I noticed that you have your instance named as Write and Read. I would typically avoid such names as they might conflict with reserved keywords, and while naming instances, it's best to name them using a camel case convention.
So, I would name them something Iike writeMc and readMc.
Hope this helps.
if you're publishing a mobile app, test on a mobile. you will get that error when using certain mobile-only code in the test environment. ie, test on an appropriate (ios/android) mobile.
I received from my client a SWC file with hundreds of png images that all have AS Linkage such as image1_1_1, image1_1_2, image1_2_1, image2_1_3 and so on. I have these same linkage names in an XML file that i'm loading.
All the images are linked with the BitmapData class as base class.
The problem is that when i try to dynamically create new bitmaps from the xml file and the linkage names by using getDefinitionByName i get the following error:
ReferenceError: Error #1065: Variable image1_1_1 is not defined.
My code for creating the bitmaps is as follows:
var BmDataClass:Class = getDefinitionByName(xmlImage) as Class;
var image:Bitmap = new Bitmap(new BmDataClass());
where xmlImage is the variable in a for each loop, looping through the xml file.
I trace xmlImage so i know it coresponds to the correct name in the SWC file.
Does anyone have any idea why i get this error?
Would appreciate any hints or solutions :-)
try this:
var imageName:String = "xxx";
var myClass:Class = getDefinitionByName(imageName) as Class;
var bmp:BitmapData = new myClass(0, 0) as BitmapData;
var img:Bitmap = new Bitmap(bmp);
The answer seems to have been as described in the accepted Answer to this thread
Instantiate a class from a string in ActionScript 3
And also slightly explained on this page
http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/
under the paragraph titled getDefinitionByName
Which for me sadly messed up a large part of the project. Ah well... new solutions presents themselves every day :-)
I have three classes and a container .swf:
Game - this loads all assets and game mechanics.
Tile - Creates a square and loads image an image via flash Var.
TicTacToe.as - This creates a game instance and is linked via container.swf
In my Game class I have the following code which works fine when I save and compile, and is able to load my images when I update to my .asp page(I am getting the data from a db and passing to flash vars).
var gridUrl:String = "img/" + loaderInfo.parameters.theme + "grid.png";
var gridPos:XMLList = theXML.GRID;
gridLoader.load(new URLRequest(gridUrl));
grid = new MovieClip();
grid.addChild(gridLoader);
When I add this code to the Tile.as to load an image for the square I get a compiler error 1009: Cannot access a property or method of a null object reference. with an error on this line:
var tileBurl:String = "img/" + loaderInfo.parameters.theme + "square.jpg";
Its working in the Game.as class but this same line isn't in my Tile.as and I can't figure out why, even locally when it can't find the variables Game.as simply lists them as "undefined" where as in Tile.as it throws a fit at loaderInfo.parameters, and loaderInfo lists them as "null". Any Help would be appreciated thanks!
It looks that in the time of calling loaderInfo object, this is not yet prepared. Try to delay execution of the code for example by adding empty frame at the begining.
I have problem when I try to run unit test when I embed an Image
[Embed(source="assets/Pen.png")]
[Bindable]
private var PenImageClass:Class;
private var penCursor:Bitmap= (new PenImageClass());
the error message is :
unable to resolve 'assets/Pen.png' for transcoding
but when I commented the [Embed(source="assets/Pen.png")] It works correctly.
>
How can I resolve this.
try to add the assets folder directly beside the as file, the Flex Unit should understand that.
I have a .swf file that uses the following code:
private function onClick(e:MouseEvent):void {
var popUpClass:Class = getDefinitionByName(e.currentTarget.popUp) as Class;
popUpContent = new popUpClass();
}
However when I load that swf into another "container" swf I am getting a Reference Error #1065. I have been reading several posts on stack overflow (for example, this one and this one) but I am still confused as to what to do.
For example, do I change the code in my "loaded swf" to reference it's own application domain (not the domain of the container swf?) and if so, how do I do this exactly?
OR do I load the swf file and assign it it's own application domain in the code of the container? (not the code for the loaded swf?)
Also, my "e.currentTarget.popUp" just has a short name "PopUpWhateverName" should I be giving it a full package name like "com.MyLoadedSwf.Assets.PopUpWhateverName"?
Yes , full package name : getDefinitionByName("com.MyLoadedSwf.Assets.PopUpWhateverName")
but You can also try :
var popUpClass:Class = e.currentTarget.popUp.constructor;
popUpContent = new popUpClass();