PDA

View Full Version : Accessing a MovieClip...


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...

justlost
06-11-2008, 07:05 AM
All I can think of is, make sure the mur_horizontal instance is not null, meaning that it is created at(or before) the frame containing your code. Also make sure your spelling is correct ;).

matleouf
06-12-2008, 10:16 AM
I thought of that, and that's why I used mur_horizontal.name in my code to access the name of that instance, and it returns correctly "mur_horizontal".
It's even more strange because of that...