|
List Info
Thread: Accessing Variables from Outside class.
|
|
| Accessing Variables from Outside class. |

|
2007-07-13 02:06:11 |
How do access variables from outside a class? I generated
variables within a
class, but I can't access them from other classes, and I
want to keep a
tally that exists outside a single class. Please help, I
spent 8 hours today
looking for ways to access this correctly, and nothing
works. Not
getChildByName, since that only lets me access properties,
and I need to
access variables. Thanks.
--
~ Elmer Tucker
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| AW: Accessing Variables from Outside
class. |
  Switzerland |
2007-07-13 03:30:26 |
When you have a public variable in class A that you want to
access in class
B you just create an instance of A inside B:
// A.as
class A{
var someVar:Number;
function A(){
someVar = 77;
}
}
----------------------------
// B.as
class B{
var a:A;
function B(){
a = new A();
trace(a.someVar);
}
}
-----------------------------
// testB.fla
var b:B = new B();
hth
-------------
Andreas Weber
-----Ursprüngliche Nachricht-----
Von: flashnewbie-bounces chattyfig.figleaf.com
[mailto:flashnewbie-bounces chattyfig.figleaf.com]Im
Auftrag von Elmer
Tucker
Gesendet: Freitag, 13. Juli 2007 09:06
An: flashnewbie chattyfig.figleaf.com
Betreff: [Flashnewbie] Accessing Variables from Outside
class.
How do access variables from outside a class? I generated
variables within a
class, but I can't access them from other classes, and I
want to keep a
tally that exists outside a single class. Please help, I
spent 8 hours today
looking for ways to access this correctly, and nothing
works. Not
getChildByName, since that only lets me access properties,
and I need to
access variables. Thanks.
--
~ Elmer Tucker
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| Re: Accessing Variables from Outside
class. |

|
2007-07-13 07:12:32 |
On 7/13/07, Elmer Tucker <elmer.tucker gmail.com> wrote:
> How do access variables from outside a class? I
generated variables within a
> class, but I can't access them from other classes, and
I want to keep a
> tally that exists outside a single class. Please help,
I spent 8 hours today
> looking for ways to access this correctly, and nothing
works. Not
> getChildByName, since that only lets me access
properties, and I need to
> access variables. Thanks.
Not recommended is to make them public:
class Foo {
public var foobar : String;
...
}
A better way is to use a getter/setter:
class Foo {
var _foobar : String;
public function get foobar () : String {
return _foobar;
}
public function set foobar ( s : String ) : Void {
_foobar = s;
}
...
}
Of course, you need a reference to the class instance who's
variables
you want to access:
class Bar {
var foo : Foo;
public function Bar ( f : Foo ) {
foo = f;
}
...
}
Does that solve your problem? Otherwise you will have to be
more specific.
Mark
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| Re: Accessing Variables from Outside
class. |

|
2007-07-13 07:14:58 |
On 7/13/07, Andreas Weber <webweber gmail.com> wrote:
> When you have a public variable in class A that you
want to access in class
> B you just create an instance of A inside B:
>
> // A.as
> class A{
> var someVar:Number;
> function A(){
> someVar = 77;
> }
> }
If a variable always has the same value, make it static:
class Foo {
static var foobar : String = "Foo. Bar.
Happiness.";
}
...and access it as Foo.foobar.
Mark
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| RE: Accessing Variables from Outside
class. |
  United States |
2007-07-13 09:12:14 |
Agreed, only make class variables public if you have to (for
example, if
you are using a class that has to have public variables
stated, like
EventDispatcher). Otherwise, I always make all my class
variables
private and use getters and setters.
Jason Merrill
Bank of America
GT&O Learning & Leadership Development
eTools & Multimedia Team
>>-----Original Message-----
>>From: flashnewbie-bounces chattyfig.figleaf.com
>>[mailto:flashnewbie-bounces chattyfig.figleaf.com] On
Behalf
>>Of Mark Winterhalder
>>Sent: Friday, July 13, 2007 8:13 AM
>>To: Flashnewbie Mailing List
>>Subject: Re: [Flashnewbie] Accessing Variables from
Outside class.
>>
>>On 7/13/07, Elmer Tucker <elmer.tucker gmail.com> wrote:
>>> How do access variables from outside a class? I
generated variables
>>> within a class, but I can't access them from
other classes,
>>and I want
>>> to keep a tally that exists outside a single
class. Please help, I
>>> spent 8 hours today looking for ways to access
this correctly, and
>>> nothing works. Not getChildByName, since that
only lets me access
>>> properties, and I need to access variables.
Thanks.
>>
>>Not recommended is to make them public:
>>
>>class Foo {
>> public var foobar : String;
>> ...
>>}
>>
>>A better way is to use a getter/setter:
>>
>>class Foo {
>> var _foobar : String;
>> public function get foobar () : String {
>> return _foobar;
>> }
>> public function set foobar ( s : String ) : Void
{
>> _foobar = s;
>> }
>> ...
>>}
>>
>>Of course, you need a reference to the class
instance who's
>>variables you want to access:
>>
>>class Bar {
>> var foo : Foo;
>> public function Bar ( f : Foo ) {
>> foo = f;
>> }
>> ...
>>}
>>
>>Does that solve your problem? Otherwise you will
have to be
>>more specific.
>>
>>Mark
>>_______________________________________________
>>Flashnewbie chattyfig.figleaf.com
>>To change your subscription options or search the
archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training
>>http://www.figleaf.com http://training.figleaf.c
om
>>
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| Re: Accessing Variables from Outside
class. |

|
2007-07-13 13:34:20 |
On 7/13/07, Kerry Thompson <alpha cyberiantiger.biz>
wrote:
> A static variable isn't guaranteed to never change. It
probably won't, but
> it's really easy to change from the outside, given
access.
Yeah, the point I was trying to make was that it's
preferable to the
use case Andreas suggested.
> I get around this by naming things I want to stay with
all caps. That's a
> standard across a lot of languages saying "this is
a constant--don't change
> it, even if you can".
Yup, I do that, too. I use haXe instead of ActionScript,
there I can
easily set access to properties:
class Foo {
var bar (default, null) : String;
}
...declared an instance variable 'bar' that can be read from
outside
the class ('default'), but only written from the inside
('null' -- no
setter method). If I wanted to use getters/setters, I'd
write the
respective method name instead of default/null. That way, I
can
restrict access without having the overhead of a function
call, and if
the need arises during development, I can still add a setter
method
without having to change the interface.
That's just one of the haXe goodies (the type system, oh the
type
system!), but I wouldn't necessarily recommend haXe to those
who
aren't familiar and comfortable with OOP practices. It's
pretty
strict.
Mark
_______________________________________________
Flashnewbie chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashnewb
ie
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
[1-6]
|
|