Actionscript 3 does not work .. it didn't give errors - actionscript-3

I am creating a clock using this code:
var date:Date = new Date();
var time:Timer = new Timer(1000);
time.addEventListener(TimerEvent.TIMER, actualiser);
time.start();
function actualiser(e:TimerEvent){
date = new Date();
var s:uint = date.seconds;
var m:uint = date.minutes;
var h:uint = date.hours;
sec_mc.rotation =(s * 6);
min_mc.rotation =(m * 6);
heur_mc.rotation =(h * 30) +m/2;
}
But, it seems that the code is not executing, I can’t even trace anything written in constructor of my document class. When I run it nothing happens and when I try to debug I get the alert message saying:
You cannot debug this SWF because it does not contain ActionScript
What can be wrong?

Try to check the code in a new fla. Write the following in your 1st frame action panel. This does give proper output and you can see the traces in the output panel. There is no issue with the code logic. Might be some issue with the movieclip being used.
var date:Date = new Date();
var time:Timer = new Timer(1000);
time.addEventListener(TimerEvent.TIMER, actualiser);
time.start();
function actualiser(e:TimerEvent){
date = new Date();
var s:uint = date.seconds;
var m:uint = date.minutes;
var h:uint = date.hours;
trace(h+":"+m+":"+s);
}
In case of CS5 , try the following steps :
WINDOWS:
1. Quit Flash
2. In a text editor, open the jvm.ini file from the following location:
2.1. Windows XP: System Hard Disk\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash CS5\language\Configuration\ActionScript 3.0\jvm.ini
2.2. *Windows Vista or Windows7:* System Hard Disk\Users\user\AppData\Local\Adobe\Flash CS5\language\Configuration\ActionScript 3.0\jvm.ini
(You might need to turn on “show hidden files”)
3. Change -Xmx128m to -Xmx256m and save the file.

EDIT: Uhm. Is that all you have? Because you need to import the needed packages, etc. Also, are you sure you linked everything up?

Related

How (if possible) do I programatically print out a screenshot of my flash project like when using a right click print command

I would like to activate this
programatically
In order to create a screenshot, it looks like you're going to have to use BitmapData.
Here's an example that will get you started (taken from here):
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData(stage.width, stage.height);
jpgSource.draw(stage);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var imgByteData:ByteArray = jpgEncoder.encode(jpgSource);
file = new FileReference();
file.save(imgByteData, "my_screenshot.jpg");

SoundTouch Class Example

I've some classes and I'm trying to call a function of a class from main swf. But I'm getting error 1120. Here's my main fla:
import PlayerClass;
SimplePlayer.play(Sound1);
Edit:
I've found an example but now I'm still getting error.
var source:Sound = new Sound1();
var output:Sound = new Sound();
var soundTouch:SoundTouch = new SoundTouch();
soundTouch.pitchSemitones = -6;
var filter:SimpleFilter = new SimpleFilter(sound, soundTouch);
output.addEventListener(SampleDataEvent.SAMPLE_DATA, filter.handleSampleData);
output.play();
This gives me error:
Sahne 1, Katman ‘Katman 1’, Kare 1, Satır 18, Sütun 44 1120: sound tanımlanmamış özelliğinin erişimi.
When I try:
var source:Sound = new Sound1();
var output:Sound = new Sound();
var soundTouch:SoundTouch = new SoundTouch();
output.play();
I'm getting this error
ArgumentError: Error #2068: Invalid sound.
at flash.media::Sound/play()
at Adsız_08_fla::MainTimeline/frame1()
The class source is here: https://github.com/also/soundtouch-as3
All you do in every single cases is trying to play an empty sound:
var output:Sound = new Sound();//this is an empty sound
output.play();//nothing to play so error
You need to follow a tutorial on how to play a sound in Actionscript 3. I believe the Actionscript 3 docs have a fully working example. I suggest to start there.

What is wrong with my JPGEncoder

Here is my code
if (event.target.content is Bitmap)
{
infotext.text = "got something";
var image:Bitmap = Bitmap(event.target.content);
var bitmapData:BitmapData = image.bitmapData;
this.addChild(image);
var j:JPGEncoder = new JPGEncoder(100);
var bytes:ByteArray = new ByteArray();
bytes=j.encode(bitmapData);
}
else
{
throw new Error("What the heck bob?");
}
When I run a debug session everything works fine till it reaches to the line
bytes=j.encode(bitmapData);
after that nothing happens and my program just goes into limbo Please help
I made changes to the code as per your suggestion
var myImage:Bitmap =Bitmap(e.target.content);
var bitmapData:BitmapData = new BitmapData(myImage.width,myImage.height,true,0xffffffff);
bitmapData.draw(myImage);
var encoder:JPGEncoder = new JPGEncoder();
var bytes:ByteArray = encoder.encode(bitmapData);
this.addChild(myImage);
but it gets stuck again after
var bytes:ByteArray = encoder.encode(bitmapData);
What am i doing wrong here?
Pretty sure I ran into this same issue a long time ago so I pulled up my code from then that I got to work.
After reviewing the code the only thing I see different is I construct the bitMapData first and assign the image via the load function.
So I think your issue is with the construction of the bitmapData var.
The following code block was cut down from a function I created that did a lot of other image manipulation.
So basically it is a cut down version and untested but it should work.
var myImage:Image = new Image();
myImage.load( Bitmap(event.target.content) );
var bitmapData:BitmapData = new BitmapData(myImage.width, myImage.height, true, 0xffffffff );
bitmapData.draw(myImage);
var encoder:JPEGEncoder = new JPEGEncoder();
var data:ByteArray = encoder.encode(bitmapData);
this.addChild(myImage);
Just in case anyone runs into this, Make sure you are using the bytearray JPEGEncoder class, it's faster: http://www.bytearray.org/?p=775
the as3core is JPGEncoder not JPEGEncoder. JPG vs JPEG... this got me also.

zip many files with Air as3 flash

OK . I am reasonably capable, but still learning.
This is for a program I am writing in AIR.
Basicaly I am needing to grab the files of mixed type and content from a given folder and zip them.
Here is the code I have put together and it sort of works.
Problem I have is that the files in the zip all have zero byte's in them. Efectivly empty.
What have I missed or done wrong?
import flash.filesystem.File;
import flash.events.Event;
import deng.fzip.*;
var directory:File = File.desktopDirectory.resolvePath("FOLDER/");
var zip:FZip = new FZip();
var files:Array = directory.getDirectoryListing();
for(var i:uint = 0; i < files.length; i++)
{
zip.addFile(files[i].name, files[i].data);
trace(files[i].name);
}
var ba:ByteArray = new ByteArray();
zip.serialize(ba);
ba.position = 0;
var finalZIP:File = File.desktopDirectory.resolvePath("TEST.zip");
var fs:FileStream = new FileStream();
fs.open(finalZIP, FileMode.WRITE);
fs.writeBytes(ba);
fs.close();
EDIT=:
While running the code, I have noticed this in the errors panel.
....app\scripts_classes\deng\fzip\FZipFile.as, Line 362 Warning: 1106: Empty statement found where block of code expected. Did you type ';' accidentally?
and it seems to be fine from what I can see, but then I did not write the Fzip script.
File.data is only populated after a call to File.load.
For synchronous loading of bytes, look at FileStream. These docs give a rundown.

Trouble with DataEvent.UPLOAD_COMPLETE_DATA not firing

I am having some trouble with an AS3 script to upload data to the server via PHP and then return some values from the PHP upload script. I am using the FileReference.upload() function, and the files are being successfully uploaded, but the eventListener I attached to the DataEvent.UPLOAD_COMPLETE_DATA event is not triggering. Is there something I can do on the PHP end of things to manually trigger this event when the file is done uploading?
as3:
private function onFileLoaded(event:Event):void {
//var _fileReference:FileReference = event.target as FileReference;
//var data:ByteArray = fileReference["data"];
//var filename:String = fileReference.name;
var urlRequest:URLRequest = new URLRequest("http://www.arttoframes.com/canvasSystems/uploadImage.php");
urlRequest.method = URLRequestMethod.POST;
fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadComplete);
fileReference.upload(urlRequest);
}
private function onFileLoadError(event:Event):void {
fileReference.removeEventListener(Event.COMPLETE, onFileLoaded);
fileReference.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
}
private function onUploadComplete(event:Event):void {
trace("ok");
fileReference.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete);
var thumbReferenceName = fileReference.name.substr(0,fileReference.name.indexOf("."))+"_thumb"+fileReference.name.substr(fileReference.name.indexOf("."),4)+"?nocache=" + new Date().getTime()
var urlRequest:URLRequest = new URLRequest("http://www.arttoframes.com/canvasSystems/uploads/Thumbnails/"+thumbReferenceName);
var urlLoader:Loader = new Loader ();
urlLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDownloadComplete);
//urlLoader.load(urlRequest);
}
So this is a long standing bug that Adobe claims they've fixed, but at least in Flex 3 lots of people claim they can reproduce it even after Adobe says they've fixed it. And that's including yours truly.
https://bugs.adobe.com/jira/browse/FP-1419
I'd employ a work around monitoring the progress directly and when all of it has uploaded manually dispatch the event or just do your work there. There are several work arounds you can try reading the comments in Jira.