typeerror : 2007 actionscript3 - actionscript-3

I am running the following piece of code:
function letterclick(e:MouseEvent)
{
myxmllist = new XMLList(myxml.word.(#clas==e.target.name).#wordname);
for each (var word:XML in myxmllist)
{
var btn:MovieClip = createbtn(myxmllist[i]);
btn.x = 100;
btn.y = 130 + n;
addChild(btn);
n += 50;
btn.addEventListener(MouseEvent.CLICK,wordclick);
i++;
}
var a:String = e.target.name
if (a=="xx") a="x"
else if (a=="yy") a="y"
else if (a=="zz") a="z"
activeletter.text = a.toUpperCase()
}
but i have TypeError: Error #2007: Parameter text must be non-null.
Can anyone tell me what is going on and how to remove this error.

Related

AS3 Syntax error: expecting identifier before var

I get following error:
1084: Syntax error: expecting identifier before var.
this my code, I try a lot of search on Google this error, but don't have.
How I can fix it?
code:
public function setAchievements(Subject:Array, Desc:Array, Coins:Array, Score:Array, Completed:Array) : *
{
(error line here) for(var achievement:Achievement = null,var color:Color = null; this.achievements_mc.achievements_content.content_mc.numChildren > 0; )
{
this.achievements_mc.achievements_content.content_mc.removeChildAt(0);
}
var x:* = 0;
var y:* = 0;
for(var i:int = 0; i < Subject.length; i++)
{
achievement = new Achievement();
achievement.Subject_txt.text = Subject[i];
achievement.Description_txt.text = Desc[i];
achievement.Coins_txt.text = String(Coins[i]);
achievement.Score_txt.text = String(Score[i]);
if(Completed[i])
{
color = new Color();
color.brightness = -0.4;
achievement.transform.colorTransform = color;
achievement.icon.visible = true;
}
achievement.x = x;
achievement.y = y;
y = y + 125;
this.achievements_mc.achievements_content.content_mc.addChild(achievement);
}
}
The correct syntax of for / for each statement in AS3 is:
for each (var yourvariable:TypeOfVariable in list of objects)
i.e.
for (var currObject:Person in listPerson)
(where your listPerson is an ArrayCollection)
Another correct syntax is:
for (var i:int; i < list.length(); i++)
but you have written:
for(var achievement:Achievement = null,var color:Color = null;
this.achievements_mc.achievements_content.content_mc.numChildren > 0;)
This isn't a correct syntax, because ther's no link between loop variables and exit condition
Maybe you want to write
for each(var achievement:Achievement in
this.achievements_mc.achievements_content.content_mc.numChildren)
and then you can initialize
var color:Color = 0 or another value linked to iteration

TypeError: Error #1009: Cannot access a property or method of a null object reference. in for loop and array

I have a function like this
var playerArray:Array = new Array();
function lockPlayerCards(totalCards) {
if (totalCards == "all"){
for (var _loc2:int = 1; _loc2 <= playerArray.length; ++_loc2){
MovieClip(getChildByName("card" + playerArray[_loc2])).effects.gotoAndStop("block");
MovieClip(getChildByName("card" + playerArray[_loc2])).btLeft.enabled = false;
MovieClip(getChildByName("card" + playerArray[_loc2])).btRight.enabled = false;
}
}
}
but when I call this function
lockPlayerCards("all")
I have error:
TypeError:
Error #1009: Cannot access a property or method of a null object
reference. at
gaple2_fla::MainTimeline/lockPlayerCards()[gaple2_fla.MainTimeline::frame1:168]
at
gaple2_fla::MainTimeline/enterFrameControler()[gaple2_fla.MainTimeline::frame1:533]
Instead of using this code
for (var _loc2:int = 1; _loc2 <= playerArray.length; ++_loc2){
use this code
for (var _loc2:int = 1; _loc2 < playerArray.length; ++_loc2){
remove the = button so that it will work

Error #1010 in as3 when detecting collision

im getting a TypeError: Error #1010: A term is undefined and has no properties.
at Defender/checkcollision()
at Defender/gameloop()
plz tell me how to solve this one.
ill give u the as3 code
public function startDefender() {
gamelevel = 3; //need some improvements here;
isfiring = true;
gunposx = gun.x;
gunposy = gun.y;
bullets = new Array();
vehicles = new Array();
missiles = new Array();
health = 100;
hits = 0;
desiredhits = 10;
_healthmeter._healthbar.width *= health / 100;
gun.startGun();
if(gamelevel != 1){
setinterceptor();
startinterceptortimer();
}
setvehicletimer();
addEventListener(Event.ENTER_FRAME, gameloop);
}
public function checkcollision(){ //checks for any collision
//COLLISION: bullets and vehicles
if((bullets.length != 0) && (vehicles.length != 0)){
for(var _b:int = bullets.length - 1; _b >= 0; _b--){
for(var _v:int = vehicles.length - 1; _v >= 0; _v--){
if(bullets[_b].hitTestObject(vehicles[_v])){
trace("Sucks");
bullets[_b].remove();
vehicles[_v].remove();
//increase the score and update scoremeter and check for desired hits
}
}
}
}
when the bullets hit the vehicles im getting this error
TypeError: Error #1010: A term is undefined and has no properties.
at Defender/checkcollision()
at Defender/gameloop()
plz help me...
if(bullets[_b].hitTestObject(vehicles[_v])){
trace("Sucks");
bullets[_b].remove();
vehicles[_v].remove();
return;

TypeError: Error #1010: A term is undefined and has no properties. AS3

This is my code:
import flash.events.MouseEvent;
function getCombos(masterword){
var combos:Array;
var a:Array;
var i:int;
var l:int;
function nextLetter(a,l,key,used){
var i:int;
if(key.length == l){
return;
}
for(i=0;i<l;i++){
if(used.indexOf(""+i)<0){
combos[key + a[i]]="";
nextLetter(a,l,key + a[i],used + i);
}
}
}
a = masterword.split("");
l = a.length;
for (i = 0; i < a.length; i++) {
combos[a[i]] = "";
nextLetter(a, l, a[i], "" + i);
trace("good")
}
return combos;
}
btnSolve.addEventListener(MouseEvent.CLICK, solve)
function solve(Event:MouseEvent){
var wordString = wordTxt.text
getCombos(wordString);
}
I have no idea what is wrong with this...
Any help here? I'm not that great with AS3 and the syntax.
BTW I am trying to make a Scrabble Solver.

Error #1009: Cannot access a property or method of a null object reference

I get the #1009 error while it visually works, can someone help me? Thanks in advance.
arrBellen is a Array on field-level.
private function bellenSpel(mv:MovieClip,x:Number):void{
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
if(landschap.x == x){
mv.visible = true;
mv.mouseEnabled = true;
}
else{
mv.visible = false;
mv.mouseEnabled = false;
}
landschap.lblScore_onderwater.text.text = "Score: " + vogelTimer.currentCount;
if(vogelTimer.currentCount % 300 == 0) {
var bel:Bel = maakBellen();
arrBellen.push(bel);
}
for(var i = 0;arrBellen.length - 1;i++){
var bl:Bel = arrBellen[i];
bl.y += 2; // output says error is here
}
}
I think either your array isn't pospulated with the objects you think it is, or they can't cast to type Bel.
instead of:
var bel:Bel = maakBellen();
do like:
var bel:Bel = new maakBellen();
Okay here's my assumptions up front... A mgraph is right or maakBellen() is actually a function that returns an instance of Bel
you have an error in your loop condition you have:
for(var i = 0;arrBellen.length - 1;i++){
var bl:Bel = arrBellen[i];
bl.y += 2; // output says error is here
}
you should have
for(var i = 0;i < arrBellen.length;i++){
var bl:Bel = arrBellen[i];
bl.y += 2; // output says error is here
}
I'm a bit confused as to why this is causing a NPE rather than an OutOfRange type error.