SoundTouch Class Example - actionscript-3

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.

Related

AS3 Error 1046 & 1180

I am trying to make a data grid were name and score is added to it.
I keep getting an error...
1046 Type was not found or was not a complile-time constant: DataProvider.
1080 Call to a possibly undefinded method DataProvider
and here is my coding...
var scoreArray = new Array();
D_G.addColumn("player");
D_G.addColumn("score");
enter_btn.addEventListener(MouseEvent.CLICK, saveScore);
function saveScore(event:MouseEvent):void
{
var obj:Object = new Object();
obj.player = tb_name.text;
obj.score = int(tb_score.text);
scoreArray.Push(obj);
scoreArray.sortOn("score", Array.DESCENDING | Array.NUMERIC);
var dp:DataProvider = new DataProvider (scoreArray);
D_G.dataProvider = dp;
}
That error happens when you're not including the class you want to use.
Are you using
import fl.data.DataProvider ??
You need to import the DataProvider class ;
import fl.data.DataProvider;

AS3 FLASH AIR - Loader not finding url

I'm having an issue with loading an image using the Loader class.
Can someone see what I'm doing wrong?
// get file folder location
var file = new File(File.applicationStorageDirectory.nativePath);
// convert to string
var fileString:String = file.url.toString();
// remove string characters
fileString = fileString.split('file:///').join('');
// create loader
var loader:Loader = new Loader();
// create request
var urlReq:URLRequest = new URLRequest(fileString+'/logo.jpg');
// load request
loader.load(urlReq);
When I test it gives me a 'Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.' If I use a loader.contentLoaderInfo to check IOERROR.IO_ERROR it gives me '1119 Access of possibly undefined propety IOERROR through a reference with static type flash.display:Loader'
Any thoughts to what I'm doing wrong? I've also tried just loading the .jpg from the same folder
var urlReq = new URLRequest('logo.jpg');
that the test app is in but still get the "URL Not Found"
Any help would be greatly appreciated.
Thank you.
This is simple: Don't use Loader, use FileStream instead. Since the file is saved into the app storage dir (or I assume it is, at least), you can read it directly rather than using a Loader.
var file:File = File.applicationStorageDirectory.resolvePath( "logo.jpg" );
var fs:FileStream = new FileStream();
fs.open( file, FileMode.READ );
var bmp:Bitmap = fs.readObject();
fs.close();
this.addChild( bmp );
You should avoid using Loader as much as possible. There is a lot of extra weight in the Loader class that adds can be a drain on performance. Use Bitmap instead, which is the lowest level way of display an image, and wrap it in a Sprite (or use Image instead of Bitmap and Sprite if using Flex) if you need to give it interactivity.

Cannot access a property or method of a null object reference Flex

I've been trying to learn flex/flash programming and am working on a project where I need to populate a spinner list in flex dynamically from a string. I have a function that separates the string using "split" and now I need to populate an array list. I have been working with this stupid big for hours now and can;t find help anywhere. I keep getting the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at views::CommonPlaces/initApp()[/Users/twing207/Documents/Adobe Flash Builder 4.6/AmericanTaxi/src/views/CommonPlaces.mxml:30]
My code is here:
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
import spark.events.IndexChangeEvent;
var Arr1:Array;
var Arr2:Array;
var Arr3:Array;
[Bindable]
public var CommonPlacesArray:ArrayList;
var CommonPlacesData:String = new String("2133664:American Taxi Dispatch, Inc:Mount Prospect:834 E RAND RD|2133665:Walmart:Mount Prospect:930 Mount Prospect Plaza|2228885:Garage:Des Plaines:1141 Lee St|2228886:Asian Island:Palatine:1202 E Dundee Rd|2229464:Kohl's:Arlington Heights:700-856 W Dundee Rd|");
var CurrentSelect:String = new String();
private function initApp():void {
Arr1 = CommonPlacesData.split("|");
var arrLength:Number = new Number(Arr1.length);
for (var i:Number = 0; i < (arrLength - 1); i++) {
CurrentSelect = new String(Arr1[i]);
Arr2 = CurrentSelect.split(":");
//THE LINE BELOW IS WHERE IT STOPS:
CommonPlacesArray.addItem(Arr2[1]);
}
}
It doesn't seem to like the "CommonPlacesArray.addItem" line. Any help or a point in the right direction would be great. Thanks in advanced!
On another note, I am also getting the error: "Access of undefined property: data" on the following:
Here in another view I set the value for data.UserCommonReturnData to a string.
function LoginLoaded (e:Event):void {
trace(e.target.data);
var ServerReturn:String;
ServerReturn = new String(e.target.data);
data.UserCommonReturnData = ServerReturn;
navigator.pushView(CommonPlaces, data);
}
and here I try to pull it back:
var CommonPlacesData:String = new String();
var CurrentSelect:String = new String();
//The next line gives the error:
CommonPlacesData = data.UserCommonReturnData;
Any idea??
You never construct CommonPlacesArray, you just declare it.
var CommonPlacesArray:ArrayList = new ArrayList();
If you check the Array List API you can also clearly see it has a constructor that accepts an array, meaning you can copy the data to it without having to iterate over it yourself.

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.

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

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?