[Flashcoders] as3 classes var query

2008-06-12 Thread Johnny Zen
Hi all

I am currently learning AS3, and I seem to be a bit confused on
understanding accessing variables outside of the class it resides in.


for example:

package test {

public class test extends Sprite {

 public var hello = hello;

}

}

I thought this var will be available to access from within another
class like this:

package test {

public class test2 extends Sprite {

 hello = hello from another class;

}

}
---

But I get :

1120: Access of undefined property hello.

Is anyone kind enough to put me right ?

Thanks


Johnny
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as3 classes var query

2008-06-12 Thread Eduardo Omine
package test
{
public class test2 extends Sprite
{
var testInstance:test = new test;
trace(testInstance.hello);
}
}

-- 
Eduardo Omine
http://blog.omine.net/
http://www.omine.net/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as3 classes var query

2008-06-12 Thread Piers Cowburn

You'd need to instantiate the other class and then access it, like this:

package test {

public class test2 extends Sprite {

public function test2(){
var testInstance:test = new test();

trace(testInstance.hello);
}

}

}



Also, it's good practice to capitalise your class names: Test, Test2  
rather than test, test2.


Piers



On 12 Jun 2008, at 13:33, Johnny Zen wrote:


Hi all

I am currently learning AS3, and I seem to be a bit confused on
understanding accessing variables outside of the class it resides in.


for example:

package test {

public class test extends Sprite {

 public var hello = hello;

}

}

I thought this var will be available to access from within another
class like this:

package test {

public class test2 extends Sprite {

 hello = hello from another class;

}

}
---

But I get :

1120: Access of undefined property hello.

Is anyone kind enough to put me right ?

Thanks


Johnny
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[EMAIL PROTECTED]
0207 631 3278


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] as3 classes var query

2008-06-12 Thread Merrill, Jason
You'd need to instantiate the other class and then access it, 
like this:

That's one way, the other way is to use static variables:

package com
{
class MyClass
{
public static var name:String = Johnny;

//or declare as a public constant:
public static const FRUIT:String = apple;
}
}


import com.MyClass

trace(MyClass.name);
trace(MyClass.FRUIT);


Jason Merrill 
Bank of America 
Global Technology  Operations  Global Risk LLD 
eTools  Multimedia 

Join the Bank of America Flash Platform Developer Community 

Are you a Bank of America associate interested in innovative learning
ideas and technologies?
Check out our internal  GTO Innovative Learning Blog  subscribe. 

 
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as3 classes var query

2008-06-12 Thread Johnny Zen
Ah thanks for all the help everyone.

I'm slowly coming around to classes, as has been confused about when
and when not to use classes and how to access the information from
each other. interesting.

Thanks again :)

On Thu, Jun 12, 2008 at 3:38 PM, Merrill, Jason
[EMAIL PROTECTED] wrote:
You'd need to instantiate the other class and then access it,
like this:

 That's one way, the other way is to use static variables:

 package com
 {
class MyClass
{
public static var name:String = Johnny;

//or declare as a public constant:
public static const FRUIT:String = apple;
}
 }


 import com.MyClass

 trace(MyClass.name);
 trace(MyClass.FRUIT);


 Jason Merrill
 Bank of America
 Global Technology  Operations  Global Risk LLD
 eTools  Multimedia

 Join the Bank of America Flash Platform Developer Community

 Are you a Bank of America associate interested in innovative learning
 ideas and technologies?
 Check out our internal  GTO Innovative Learning Blog  subscribe.


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders