java - Flash AS3 Pass my var data to another frame -
i'm using as3 / air 3.2 android. i'm having trouble passing variable data frame. read forums i'm new don't have yet idea. have input text , button in frame 1 user input name data entered save. (i used sharedobject) data inputted appear on frame 2. while frame 2 dynamic text data appear. code 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 property or method of null object reference. think because i'm wrong in passing of data frame. attempt: tried show output on same frame , didn't encounter error.
your sharedobject
var myso
, not myso1
, , share data between frames, can use variable :
frame 1 :
... var shared_data:string = txt_input.text nextframe() ...
frame 2 :
// shared_data , use another_input.text = shared_data shared_object.data.current_name = shared_data ...
edit :
/* frame 01 */ // shared_data should declared here global var not inside function var shared_data:string submit_btn.addeventlistener(mouseevent.click, gotomynextframe) function gotomynextframe(event:mouseevent):void { // here should assign value shared_data var shared_data = yourname.text nextframe() } /* frame 2 */ stop() import flash.net.sharedobject // if redefine shared_data var here lost it's value , null value // var shared_data:string var myso:sharedobject = sharedobject.getlocal("test1") myresult.text = shared_data // here sharedobject object named myso , not sharedobject //sharedobject.data.myso = shared_data myso.data.yourname = shared_data
Comments
Post a Comment