| Ultrashock Forums
• global class properties |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
|
|
2008-02-22
#2 |
||
|
I got it to work by importing the Startup class to the other class that need it, and then assiging it within the new class; Code:
|
|
|
2008-02-22
#3 |
||
|
Couldn't you just do it this way which is maybe a little bit cleaner. ActionScript Code:
ActionScript Code:
|
|
|
|
2008-02-22
#4 |
||
|
If I set the properties as private, flash won't let me access them. But using your code for multiple properties I have this... Is this correct? Code:
class Startup
{
public static var WSDL_URL:Object = "http://www.google.com"
public static var IMAGE_URL:Object = "http://images/"
public static var uId:Object = "user"
public static var pwd:Object = "password"
//
public function Startup()
{
}
public static function get _WSDL_URL():Object // read only
{
return WSDL_URL;
}
//
public static function get _IMAGE_URL():Object // read only
{
return IMAGE_URL;
}
//
public static function get _uId():Object // read only
{
return uId;
}
//
public static function get _pwd():Object // read only
{
return pwd;
}
}
Code:
private var IMAGE_URL = doStartup._IMAGE_URL; private var WSDL_URL = doStartup._WSDL_URL; private var uId = doStartup._uId; private var pwd = doStartup._pwd; |
|
|
2008-02-22
#5 |
||
|
You can set your variables as private and use a getter to access the variable. If you were trying to access WSDL_URL directly like "Startup.WSDL_URL" then yes it would have to be public. But if you use a getter function like: ActionScript Code:
Then you can make the variable private since your not accessing it directly. But the getter would have to public since your trying to access it from another class. |
|
|
|
2008-02-22
#6 |
||
|
Thanks, is there any benefit making it private?
|
|
|
2008-02-22
#7 |
||
|
Hopefully I can explain myself correctly here. By making it private and using a getter to access that its read only which means you can't change the variable value, you can only read it. Here is a little example that I came up with and hopefully its right. Anyone please feel free to correct me if I am wrong ActionScript Code:
ActionScript Code:
|
|
|
2008-02-22
#8 |
||
|
Hi Bob, Isocase is right. Generally you would just make the vars public static *and* final/constant so that it by nature would be read only and thus safe to use without getter. AS2 doesn't support this keyword, so the constant is effectively mimiced by using a static getter function with the same name: ActionScript Code:
ActionScript Code:
|
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


7 comments
| 223 views


Linear Mode