Flash doesnt recognise JPGEncoder - actionscript-3

When I run this code
var jpgEncoder:JPGEncoder = new JPGEncoder(100);
It returns this error
Type was not found or was not a compile-time constant: JPGEncoder.
Call to a possibly undefined method JPGEncoder.
Flash doesn't recognise "JPGEncoder" as a keyword.
Can someone help me please?

JPGEncoder is not a keyword, but a class you'll need to import to utilize.
Download JPGEncoder from as3corelib and import it into your program using
import com.adobe.images.JPGEncoder;

Related

ActionScript 3 - sound mp3 is not played without error

Help me, I use Adobe Flash CS3 Professional.
// i have try using this import, but still not work
/*import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
*/
// here is the code
var req:URLRequest=new URLRequest("music.mp3");
var snd:Sound=new Sound();
snd.load(req);
var chan:SoundChannel=snd.play();// not work using 'snd.play(1);' too
chan.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
trace("Musik Complete");
}
When i run the swf or ctrl+enter, the output Musik Complete without any sound played, but the animation still played. For the animation i just create simple twin motion.
i work on this directory
C:/flash/example.fla
C:/flash/example.swf
C:/flash/music.mp3
I have try to import music.mp3 into the library too.
Note: I get the example from my friend(.swf, .fla, .mp3). I play the .swf that shared by my friend and work, but when i try to create by my self, is not work. So, i think music.mp3 was fine to use for Flash. Here is my friend code:
var Audio:musik = new musik();
var chan:SoundChannel = new SoundChannel();
// play
chan=Audio.play();
// stop
chan.stop();
// i am so confuse i run my friend project and work fine (sound and other), if i write from scrap even i write the same code, there is an error, and this the error:
// 1046: Type was not found or was not a compile-time constant: musik.
// 1180: Call to a possibly undefined method musik.
I just watch on youtube, i missing one step.
In library, open properties of music.mp3 and give it class name.
So, we can call the class using this var Audio:musik=new musik();.
Then, create the Sound Channel.
At least, function to play and stop using this:
//play
chan=Audio.play();
// stop
chan.stop();

1119: Access of possibly undefined property security through a reference with static type Class for using flash System.security.loadPolicyFile

I am developing an app and want to integrate the youtube API for Adobe Air.
However, I get the following error:
1119: Access of possibly undefined property security through a reference with static type Class.
My code is this:
import flash.system.SecurityDomain;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
System.security.loadPolicyFile("app:/crossdomain.xml");
Security.allowDomain("*");
I get this error in line 5 (System.security.loadPolicyFile("app:/crossdomain.xml");)
It seems that Flash does not even recognize this method.
Any ideas?
Cheers!
Just use
System.loadPolicyFile("app:/crossdomain.xml");

Explicit reference to actionscript class in top level package

If you define a class in actionscript that has the same name as a class in the top level package (e.g. Array) there seems to be no way of explicitly referencing the class in the top level package.
UPDATE: This issue is only appearing in Flash Builder 4.7 with the new ASC 2.0 compiler, using Flash Builder 4.6 with an 'old' Flex SDK it works.
Example:
package
{
import flash.display.Sprite;
import mypackage.Array;
public class AS3Problem extends Sprite
{
public function AS3Problem()
{
var myOwnArray:mypackage.Array = new mypackage.Array();
// The line below will cause a compile error
// 'Ambiguous reference to Array'
var flashArray:Array = new Array();
}
}
}
I know the simple solution to this problem is to not create classes with a name that is the same as an as3 top level package class/function, but I'm intrigued as to how this could be 'fixed' in some way by explicitly referring to this package or some other means.
For those interested, I happened to accidentally import 'Array' from hamcrest-as3 while writing tests which caused a problem like this.
Try removing this line
import mypackage.Array;
so you do not import this custom Array and you always use the fully qualified name, I did not tested it but this should fix it.
EDIT:
I tested this and yes you have to add this import line, it will not work , but I can't reproduce the error, I can use and custom Array and the global Array fine with no issue/error or warrning.
EDIT2:
This also worked for me, can you test this too?
var globalArray:Class=(getDefinitionByName('Array') as Class);
var arr2:*=new globalArray();
arr2.push("test");
trace(arr2);

AS3 text to file

I'm making a game in cs3 using as3. I've seen dozens of tutorials, but none of them are working for me.
I found the simplest code I could, and it still gives me an error "1061: Call to a possibly undefined method save through a reference with static type flash.net:FileReference."
here's the code I'm using:
var file:FileReference = new FileReference();
file.save("this is a text", "file.txt")
Are you importing FileReference? If not, you'll need:
import flash.net.FileReference;
..inside your package declaration (or at the top of your block of code if you're coding on the time line)
With that import included, your code works for me.

AS3 Access of undefined property error

I have code that reads a JSON file to import the information about a level in a game I'm making. The code was running and compiling fine until suddenly every time I tried to build, FlashDevelop started erroring "build failed" without actually giving an error.
I ran the code through the mxmlc compiler, to give me an error message, and it returned an error saying "Error: access of undefined property JSON" in line:
var level:Object = JSON.decode(json);
This is confusing because the JSON library is clearly included at the top of the file, "import com.adobe.serialization.json.JSON;", and this error started occurring completely on it's own, which is odd...
package
{
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import net.flashpunk.Entity;
import com.adobe.serialization.json.JSON;
public class LevelParser
{
public static function GetLevelByID(ID:int, source:Class):Level
{
// Store new entity
var populated:Vector.<Entity> = new Vector.<Entity>();
// Parse file into string
var bytes:ByteArray = new source();
var json:String = bytes.readUTFBytes(bytes.length);
var level:Object = JSON.decode(json);
// Find correct level
...
EDIT: Strangely if I comment out the line to call it, and this function, the code compiled fine in mxmlc, but in Flashdevelop is says "Build Failed" with no error
This is actually a reference error.
As of AS3 SDK 4.5, JSON became a native class within the SDK. In previous versions, you would have to download the adobe serialize classes to access JSON - which may be your issue.
When using the mxmlc, it will compile with all the included libraries specified in your sdk flex-config.xml. In FlashDevelop, it will only use the classes you include.
Solution: add the adobe serialize class to your project