I have an MXML
file with this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="30">
<mx:Script>
<![CDATA[
public function initLayer(name:String):void{
t_layer.text = name;
}
]]>
</mx:Script>
<mx:Grid id="mainGrid" width="100%" height="100%" >
<mx:GridRow>
<mx:GridItem width="80%">
<mx:Text id="t_layer" text="new" />
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Canvas>
From another AS file, I'm creating a Layer
object:
public function addLayer(name:String):void{
var layer:Layer = new Layer();
layer.initLayer(name);
layer.x = 0;
layer.y = _layers*layer.height;
layersContainer.addChild(layer);
_layers++;
}
But I'm getting an error inside initLayer
function relative to undefined property for null object t_layer
.
What am I doing wrong? Can you help me?
EDIT:
I can't believe it. Just answering Timofei and when I test my ode it works. How? I change order of the functions inside my addLayer
method like this:
public function addLayer(name:String):void{
var layer:Layer = new Layer();
layer.x = 0;
layer.y = _layers*layer.height;
layersContainer.addChild(layer);
layer.initLayer(name);
_layers++;
}
When do you call
initLayer
? Do it not earlier, thanFlexEvent.CREATION_COMPLETE
is dispatched by your canvas.