matleouf
06-08-2008, 10:37 PM
Hi !
I'm sure the problem I have has a very easy solution, but since I've spent an hour trying to figure it out, I thought I'd ask on this forum :)
There is my class (simplified as much as I can) :
package com.mat {
import flash.display.*;
import flash.events.*;
public class Objet extends Sprite {
public function Objet(pos_x, pos_y : Number) {
this.graphics.beginFill(0x506080);
this.graphics.drawCircle(pos_x, pos_y, 10);
this.graphics.endFill();
}
public function ajouteObstacle(nomObjObstacle:String) {
trace("Name : " + nomObjObstacle);
trace("Name (2) : " + getChildByName(nomObjObstacle).name);
}
}
}
And there is the code on the first frame :
import com.mat.*;
var balle:Objet = new Objet(50,50);
balle.ajouteObstacle(mur_horizontal.name);
addChild(balle);
And here is the error I got :
Name : mur_horizontal
TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
at com.mat::Objet/ajouteObstacle()
at balle_fla::MainTimeline/balle_fla::frame1()
mur_horizontal is the name of a movie clip on my stage. Sorry for the french error output...
Why can't I access the property of this MovieClip ?
I tried (getChildByName(nomObjObstacle) as MovieClip).name and this doesn't work either...
Thanks a lot for any help...
I'm sure the problem I have has a very easy solution, but since I've spent an hour trying to figure it out, I thought I'd ask on this forum :)
There is my class (simplified as much as I can) :
package com.mat {
import flash.display.*;
import flash.events.*;
public class Objet extends Sprite {
public function Objet(pos_x, pos_y : Number) {
this.graphics.beginFill(0x506080);
this.graphics.drawCircle(pos_x, pos_y, 10);
this.graphics.endFill();
}
public function ajouteObstacle(nomObjObstacle:String) {
trace("Name : " + nomObjObstacle);
trace("Name (2) : " + getChildByName(nomObjObstacle).name);
}
}
}
And there is the code on the first frame :
import com.mat.*;
var balle:Objet = new Objet(50,50);
balle.ajouteObstacle(mur_horizontal.name);
addChild(balle);
And here is the error I got :
Name : mur_horizontal
TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
at com.mat::Objet/ajouteObstacle()
at balle_fla::MainTimeline/balle_fla::frame1()
mur_horizontal is the name of a movie clip on my stage. Sorry for the french error output...
Why can't I access the property of this MovieClip ?
I tried (getChildByName(nomObjObstacle) as MovieClip).name and this doesn't work either...
Thanks a lot for any help...