PDA

View Full Version : acces of undefined property error when i try to use my package


vlad2005
05-18-2007, 10:39 AM
Ai have an simpe aplication for testing purpose, used from help:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import samples.SampleCode;
var mySample:SampleCode = new SampleCode();
mySample.sampleGreeting = "this is line with error";
]]>
</mx:Script>
</mx:Application>

This is package

package samples
{
public class SampleCode
{
public var sampleGreeting:String;
}
}

Import package is ok, but i have error on line with "mySample.sampleGreeting" that say "Acces of undefined property mySample".
From where is this error?

flexy
05-18-2007, 11:33 AM
I think you're calling an instance of SampleCode before the application has had a chance to initialise it. By waiting for the creationComplete event, and then doing a callback to init() it seems to work fine.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import samples.SampleCode;
private var mySample:SampleCode = new SampleCode();

private function init() :void
{
mySample.sampleGreeting = "this is line with error";
}

]]>
</mx:Script>
</mx:Application>

vlad2005
05-18-2007, 11:56 AM
Work. Thanks!
But now i have a new problem, warning at line where make instance of class SampleCode, "var mySample:SampleCode = new SampleCode();"
This error say:

1084: var 'mySample' will be scoped to the default namespace: greeterClass: internal. It will not be visible outside of this package.

Class have atribute "public" so why i have this warning?

flexy
05-18-2007, 12:19 PM
Have look closely at the code above where I declare mySample; can you see the difference?

Your variable doesn't have a scope.

vlad2005
05-18-2007, 07:27 PM
Work. Thanks!