AS3 Error 1046 & 1180 - actionscript-3

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;

Related

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.

The supplied DisplayObject must be a child of the caller DisplayObjectContainer/setChildIndex()

I don't know where is the problem
I will very thankful for the person who will explain to me .
I need any kind person to answer me .This is my whole code nothing else .The problem which i faced is
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/setChildIndex()
at CreateSimpleDynamicRolloverswithAs3_fla::MainTimeline/rolloverF()
even I make this code as comment the error still persists
images_mc.setChildIndex(evt.currentTarget as MovieClip, numChildren-1);
import fl.transitions.easing.*;
import flash.display.Shape;
import fl.transitions.Tween;
import flash.events.MouseEvent;
import flash.display.MovieClip;
var imgBorder:Shape = new Shape();
imgBorder.graphics.lineStyle(5,0xffffff,1,true,"normal");
imgBorder.graphics.drawRect(0,0,250,120);
addChild(imgBorder);
imgBorder.visible = false;
images_mc.addEventListener(MouseEvent.MOUSE_OVER , rolloverF);
images_mc.addEventListener(MouseEvent.MOUSE_OUT , rolloutF);
function rolloverF(evt:MouseEvent):void{
imgBorder.visible = true;
var borderTween:Tween = new Tween(imgBorder,"alpha",Strong.easeOut,0,1,1,true);
var borderW:Tween = new Tween(imgBorder,"width",Strong.easeOut,255,280,1,true);
var borderH:Tween = new Tween(imgBorder,"height",Strong.easeOut,125,137,1,true);
var imgW:Tween = new Tween(evt.currentTarget,"width",Strong.easeOut,255,280,1,true);
var imgH:Tween = new Tween(evt.currentTarget,"height",Strong.easeOut,125,137,1,true);
trace (images_mc.mc1.name);
imgBorder.x = evt.currentTarget.x;
imgBorder.y = evt.currentTarget.y;
//even i make this code as comment error sitll persists
images_mc.setChildIndex(evt.currentTarget as MovieClip, numChildren-1);
//trace(images_mc.mc1.name);
}
function rolloutF(evt:MouseEvent):void{
var borderTweenBack:Tween = new Tween(imgBorder,"alpha",Strong.easeOut,1,0,1,true);
var borderWBack:Tween = new Tween(imgBorder,"width",Strong.easeOut,280,255,1,true);
var borderHBack:Tween = new Tween(imgBorder,"height",Strong.easeOut,137,125,1,true);
var imgWBack:Tween = new Tween(evt.currentTarget,"width",Strong.easeOut,275,250,1,true);
var imgHBack:Tween = new Tween(evt.currentTarget,"height",Strong.easeOut,132,120,1,true);
}
This is a logic problem. You add rolloverF listener to images_mc so images_mc will be the currentTarget. Next you want images_mc to set the index of the currentTarget which is impossible since the currentTarget is images_mc itself. Maybe you mean evt.target?
Also setChildIndex(evt.currentTarget as MovieClip, numChildren-1) or addChildAt(evt.currentTarget as MovieClip, numChildren-1) both translate to a simple addChild().

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.

Flash Builder + JSON + ac3corelib = error

I'm trying to receive an array using URLLoader. I included ac3corelib to my project and declared JSON library: "import com.adobe.serialization.json.JSON;" However, when I use "JSON.decode(e.target.data)" I get an error "Access of undefined property JSON".
Here is the code:
import com.adobe.serialization.json.JSON;
private function getContacts():void {
var contacts:URLLoader = new URLLoader();
contacts.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
var con:Object = JSON.decode(e.target.data);
}
contacts.load(new URLRequest("http://domain.com/cmd.php?action=contacts"));
}
Thanks in advance!
Use the below code
var con:Object = com.adobe.serialization.json.JSON.decode(e.target.data);
instead of
var con:Object = JSON.decode(e.target.data);
Dont forget to import below package
import com.adobe.serialization.json.JSON;
its working good for me!

How do I add verticallayout to a bordercontainer on runtime?

I'm creating a bordercontainer on runtime:
var bcArtist:BorderContainer = new BorderContainer();
var imgArtist:Image = new Image();
var lblArtist:String = new String();
bcArtist.id = artistXML.pk_artist_id;
bcArtist.width = 75;
bcArtist.layout = VerticalLayout;
But the last line gives this error:
1067: Implicit coercion of a value of type Class to an unrelated type spark.layouts.supportClasses:LayoutBase.
I feel it is something very easy, but haven't figured it out yet.
The layout property accepts an object of type LayoutBase but you are giving it the class itself. Try:
bcArtist.layout = new VerticalLayout();
VerticalLayout is the class. You need to create an instance of it.
bcArtist.layout = new VerticalLayout();