Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {name: "Angel"} is the LITERAL representation of a generic object or JSON.
- All classes inherit from Object.
- You really need to read more about Object Oriented Programming.
- So, the SharedObject.data property, is a getter, that first reads the .so file, parse the data, and returns a generic object with all the key/values pairs. You just need to iterate through the elements of such object, or accessing the values directly by their keys:
- //Object
- var localData:Object = {};
- localData = so.data;
- for(var i:String in localData)
- {
- trace( "Key:" + i + " Value: " + localData[ i ] ) ;
- }
- Or:
- trace( localData.levelNumber );
- You will get what you saved. If you saved an array, you will get an Array. If you saved a boolean, you will get a Boolean.
- The thing is, if you use an if statement like this:
- if( localData.score )
- It will return true, regardless of if 'score' is true or false, because that is checking for null, not for true/false.
- Example:
- var localData:Object = { name: "Angel" };
- if( localData.score )
- {
- //The body of the if statement will not execute, because score is null
- }
- Now, let's add a Boolean:
- var localData:Object = { name: "Angel", "hasLives": false };
- if( localData.hasLives )
- {
- // The body of the if statement will execute, because, although hasLives is false, it will return true because hasLive is not null
- }
- So in your case, you need to do both checks:
- if( localData.hasLives && localData.hasLives == true)
- {
- //Now, this won't be executed because one of the conditions
- didn't met. That means, hasLives is not null, but it is false.
- }
- An object returns true, not only if it's a boolean set to true, but also if it's not null or it's not undefined.
- An object returns false if it's null and it's undefined, so when we do this:
- if( object )
- We are just checking if it's not null and if it's not undefined.
- So to check if it's true or false (boolean), we explicitly check it:
- if( object == true )
- {
- }
- Let's take this example:
- var localData:Object = {"musicIsOn": null};
- if( localData.musicIsOn )
- {
- //This will NOT be executed, because musicIsOn is defined as null, that means it's null, although the key 'musicIsOn' exists in the object.
- }
- Another example:
- trace( localData.musicIsOn == null ); //true
- trace( localData.musicIsOn == undefined ); //true
- It returns true in both cases because musicIsOn is null, and as it is null, it is also undefined.
- Other literal representations:
- Array:
- []
- Object:
- {}
- Vector:
- <TypeHere>[]
- String:
- ""
- Number:
- 123.99
- int:
- 55
- Function:
- function():void{}
- Boolean:
- true / false
- Expressions:
- ()
- XML:
- <>
- uint:
- 0xff0000
- Not a Number:
- NaN
- Regular Expressions:
- / /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement