AS3 #1008 Error, Level Change - actionscript-3

I know Im probably missing something stupidly easy, but Im trying to set up a level change in my game. Once the score variable hits 100 I want some dynamic text to change to Level 2, instead it gives me a null error specifically
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Cat_fla::MainTimeline/NextLevel()"
Here is the code:
var level:Number = 1;
addEventListener(Event.ENTER_FRAME,NextLevel);
function NextLevel(event:Event):void{ //Checks if player is at next level pionts. Changes Level count.
if (score==100) {
level += 1;
}
levelCount.text = "Level: " +String(level);
}
It specifically pulls up " levelCount.text = "Level: " +String(level); " . So I imagine its to do with the String being there depite being declared as a Number, but I used a similar system to keep score and that worked fine.

Related

AS3 : 2 error 1061 and an error 1119

Sorry ahead of time for french in my code or badly translated errors (idk what they are in english so Google translate). I'm working on a program at school to add all numbers, all even numbers or all odd numbers (different buttons) from an array (seperate file, called U2A2_Elements.as) and I'm getting multiple errors, I'm getting :
1061: Call for indexOf method might not be defined via the static int type reference at entier = (entier.indexOf(entierSaisi));
1119: Access to the length property can not be defined via the reference type static int" at for (var i=entier; i entier.length; i++).
1061: Call for pop method might not be defined via the reference type static int" at entier.pop();.
Any help would be greatly appreciated as I have no idea what to do with the code nor does the teacher or anyone else.
EDIT: Forgot to put the link to the code http://pastebin.com/5nyf3z7g
In your supprimerFunction() function, you forgot that your array is mesEntiers ( and not entier which is an int object ), so I think that you should write :
function supprimerFunction(event:MouseEvent):void {
var entierSaisi:String;
var entier:int;
entierSaisi = (txtEntier.text);
entier = int(entierSaisi);
entier = mesEntiers.indexOf(entier);
if (entier != -1) {
for (var i = entier; i < mesEntiers.length; i++) {
entier[i] = entier[i + 1];
}
mesEntiers.pop();
}
}
Of course, I try just to remove errors mentioned in your question, and not improve your function.
Hope that can help.

Google Docs Script Issue with Split through Function

First time poster here for Google Script related services, hopefully I put it in the right place! I'm encountering an error and I can't seem to find the right terminology to look up a solution. Below is the function. Within it I have a variable, string1, that I apply the split to. If I hard-code the value of the string (in the line commented out in the string), then it works and I receive the correct output. If, on the other hand, I try to pass that string into the function from another function, I receive the following error:
"TypeError: Cannot find function split in object Wed Oct 30 2013 09:00:26 GMT-0400 (EDT),danno,ticket,netid,request,mac,Error - Invalid Mac / Mac Not Found."
Note: My call to the function looks like this - formatEmailRow(completeEmailArray[i])
function formatEmailRow(rowToFormat) {
var formattedString = "";
var array1 = [];
var string1 = "";
///////////////////////
string1 = rowToFormat;
//string1 ="10/30/2013 9:00:26,danno,ticket,netid,request,mac,Error - Invalid Mac / Mac Not Found ";
///////////////////////
array1 = string1.split(",| ,|, ");
if (array1 != ""){
for (var i = 0; i < array1.length; i++) {
formattedString = formattedString + " " +(array1[i]);
}}
return formattedString;
}
Please help!
Thanks ahead of time, any advice is appreciated!
-Danno
You're getting that error because .split() isn't a method contained in the type of object you've passed in. Since you're new to this, it's worth a pause to read up on Objects and Methods - this is a quick overview.
You want to receive a String, but it seems that you're not. The problem will be with the code that's calling formatEmailRow().
My guess is that you're passing an array - probably all the cells in a row - but here's how you can check.
Add this line as the first line in your function:
Logger.log("rowToFormat = " + JSON.stringify(rowToFormat));
... then run, with your error. Check the logs - you want to see that you are getting a simple string. If you're getting an array, then you know what you need to fix. (Maybe you want to get the array after all!)

Can't reference a child with a variable instance name [syntax]

I want to generate villagers for my game and then organize them into a list but I'm having a bit of difficulty, here is what it's supposed to look like and here is what it actually looks like. The code for generating kinsmen is:
var k = new kinsmen ;
menuArea.kinsmenDivider.addChild(k);
totalKinsmen++;
totalKinsmenAlive++;
k.name = "kinsmen" + totalKinsmen;
The code used for sorting them is:
for (var i:int = 1; i < (totalKinsmen+1); i++) {
if (menuArea.kinsmenDivider.getChildByName("kinsmen"+i) !=null) {
menuArea.kinsmenDivider["kinsmen" + i].y = menuItemCount * 107.5;
menuItemCount++;}}
That should look through the ID's of every kinsmen that's ever existed and when it finds the ID of one that's alive it should give it a place in the menu and continue going through the other IDs.
trace ("kinsmen" + totalKinsmen);
trace (menuArea.kinsmenDivider.getChildByName("kinsmen"+i));
Both always have the same values in my tests. The debugger posts the following error during runtime:
TypeError: Error #1010: A term is undefined and has no properties.
When I remove ["kinsmen" + i] it stops giving errors and the entire menu moves down each time a new kinsmen is generated so I know that's the part causing the issue but I don't know why or how to fix it and would appreciate help, all the above code is in my document class. I only started coding AS3 a few days ago so I'm still a bit shaky. Cheers for reading.
You access the clip correctly everywhere except
menuArea.kinsmenDivider["kinsmen" + i].y
shouldn't it be :
menuArea.kinsmenDivider.getChildByName("kinsmen" + i).y

Trouble accessing Array Elements

I'm creating this array.
var GPA_Array:Array=new Array();
var dg:DataGrid= new DataGrid();
gpaBuild();
function gpaBuild()
{
dg.columns=["Num","Course","Grade","Credits"];
GPA_Array.push({Num:"1",Course:"ADS",Grade:"A+",Credits:"4"});
GPA_Array.push({Num:"1",Course:"ADD",Grade:"A+",Credits:"4"});
dg.dataProvider=new DataProvider(GPA_Array);
}
after pushing data in the array ,i need to accees Grade and credits.
I have tried this method,
GPA_Array[0][1],GPA_array[0][2] ,
but it didn't work.
If i try to trace it
trace(GPA_Array[0][1])
it gives me undefined .
also ,when i use trace(GPA_array.toString), it gives me error.
Your push() method appears to be pushing an object into your array, so GPA_Array[0][1] will likely throw an exception. Treating each item in the array as an object and using object notation, you should be able to access it with something like:
Object gpaEntry = GPA_Array[0];
trace("gpaEntry {Num:" + gpaEntry.Num + ",Course:" + gpaEntry.Course + ",Grade:" + gpaEntry.Grade + ",Credits:" + gpaEntry.Credits + "});

ActionScript – Default Datatype for Untyped Variables?

if i don't specifically type a variable in my code will it compile as a default datatype? for example, the "for each ... in" function works best without typing the variable:
for each (var element in myArray)
{
//process each element
}
does my element variable have a datatype? if it is typed as Object is it better to actually write element:Object or does it matter?
EDIT
actually, that was a bad example, since the element variable is going to be typed to whatever element is in myArray.
but is that how it works if a variable is untyped? it will simply become what is passed to it?
here's a better example for my question:
var a = "i'm a string"; //does this var becomes a String?
var b = 50.98; //does this var becomes a Number?
var c = 2; //does this var becomes an int?
for each (var element in myArray)
The element variable doesn't have any data type - it is untyped and thus can hold anything.
And yeah, it is equivalent to writing element:Object or element:*, but it is always advisable to type your variables - this will help you catch some errors before you run the code. The mxmlc compiler will emit a warning if you don't do this, which can be fixed by typing it as e:Object or e:*.
var a = 45.3; //untyped variable `a`
a = "asd"; //can hold anything
/*
This is fine: currently variable `a` contains
a String object, which does have a `charAt` function.
*/
trace(a.charAt(1));
a = 23;
/*
Run time error: currently variable `a` contains
a Number, which doesn't have a `charAt` function.
If you had specified the type of variable `a` when
you declared it, this would have been
detected at the time of compilation itself.
*/
trace(a.charAt(1)); //run time error
var b:Number = 45.3;
b = "asd"; //compiler error
trace(a.charAt(1)); //compiler error