Reputation: 1
I'm using AS3 / AIR 3.2 for Android. I'm having a trouble about passing my variable data to another frame. I read some forums about this but I'm only new this so I don't have yet any idea. I have an input text and button in my frame 1 where the user will input a name then the data entered will be save. (I used SharedObject) but all the data inputted will appear on frame 2. While my frame 2 is a dynamic text where all the data will appear. This is the code for my frame 1
import flash.net.SharedObject;
var myName:String;
myResult.text = "";
var mySO:SharedObject = SharedObject.getLocal("test");
if (mySO1.data.myName != null){
myResult.text = mySO1.data.myName;
}
else {
myResult.text = "No Name";
}
submit_btn.addEventListener(MouseEvent.CLICK, gotomyNextFrame);
function gotomyNextFrame(event:MouseEvent):void
{
nextFrame();
myName = myInputName.text;
trace(myName);
myResult.text = myName;
mySO.data.myResult = myInputName.text;
mySO.flush();
trace(mySO.data.myResult);
}
Error: Error #1009: Cannot access a property or method of a null object reference. I think this is because I'm wrong in passing of data into frame. Attempt: I tried show the output on the same frame and I didn't encounter any error.
Upvotes: 0
Views: 1188
Reputation: 9839
Your SharedObject
var is mySO
and not mySO1
, and to share data between frames, you can use a variable like this :
frame 1 :
...
var shared_data:String = txt_input.text
nextFrame()
...
frame 2 :
// get shared_data and use it as you like
another_input.text = shared_data
shared_object.data.current_name = shared_data
...
Edit :
/* frame 01 */
// shared_data should be declared here to be a global var not inside a function
var shared_data:String
submit_btn.addEventListener(MouseEvent.CLICK, gotomyNextFrame)
function gotomyNextFrame(event:MouseEvent):void {
// here you should just assign a value to shared_data var
shared_data = yourName.text
nextFrame()
}
/* frame 2 */
stop()
import flash.net.SharedObject
// if you redefine shared_data var here you will lost it's value and you will get a null value
// var shared_data:String
var mySO:SharedObject = SharedObject.getLocal("test1")
myResult.text = shared_data
// here your SharedObject object is named mySO and not SharedObject
//SharedObject.data.mySO = shared_data
mySO.data.yourName = shared_data
Upvotes: 1