Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Transfer variables from one frame to another

Explorer ,
Jul 22, 2009 Jul 22, 2009

Hi,

How would I go about transfering variables from one from to another?

What I want to do is send data from the first frame to a database then retrieve info back and populate form field on the second frame.

At the moment I have the code within the second frame doing everything! What want is to send the username and password enter in the first frame textboxes to a database then displaying the returned info on the second frame.

I already have working php code so this isn't a problem.

Thanks,

Nightwalker

TOPICS
ActionScript
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Jul 23, 2009 Jul 23, 2009

Download and review my attached Fla file. The variable is defined on the first frame. It can be accessed from every other frame in the movie that the "Actionscript" layer extends to.

Enjoy.

Translate
LEGEND ,
Jul 22, 2009 Jul 22, 2009

When I want to have code shared along the timeline I dedicate a layer that extends the length of the timeline without interuption--with everything I want to share defined/assigned in the first frame of the layer.  That way, whatever variables and functions in that layer are available anywhere along the timeline

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2009 Jul 22, 2009

Ah ok! I didn't realize I could have two action layers at a time running! I will try that.

Edit:

This is the code I am using for the second frame to display the data from the database:

this["btnSubmit"].addEventListener(MouseEvent.CLICK, submitVars);

//Create the loader object
var Dataloader:URLLoader = new URLLoader();
//Createthe URLRequest object to specify the file to be loaded and the method ie post
var dataurl:String = "http://localhost/flash/dynamicWebsite/getData.php";
var prodreq:URLRequest = new URLRequest (dataurl);
prodreq.method = URLRequestMethod.POST;
prodreq.data = variables;
function submitVars(event:Event):void {
    variables.username = tiUser.text;
    Dataloader.load(prodreq);
    }
   
    function loaddata(event:Event) {
            var v:URLVariables = new URLVariables(event.target.data);

        tiCustomerID.text = v.cid;
        tiFName.text = v.fname;
        tiLName.text = v.lname;
        tiSNum.text = v.snum;
        tiSName.text = v.sname;
        tiSuburb.text = v.suburb;
        tiPCode.text = v.pcode;
        tiCountry.text = v.country;
        tiPhone.text = v.phone;
        tiEmail.text = v.email;
        tiPass.text = v.upassword;
        }
        Dataloader.addEventListener(Event.COMPLETE, loaddata);

Dataloader.addEventListener(Event.COMPLETE, contentSaved);
function contentSaved(event:Event):void {
var v:URLVariables = new URLVariables(event.target.data);
status_txt.text = "customer: " + v.cid + " loaded";
}

This code works when its same frame as the objects but if move it to the first frame where the login code is it doesn't work. I've tried putting the framename where the objects are located before code in the loaddata function both written like:

customerDetails.tiCustomerID.text = v.cid;

And

["customerDetails"]tiCustomerID.text = v.cid;

However, the variables are still not being put in the boxes on the second form.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 23, 2009 Jul 23, 2009

As the previous poster said, you can have a separate layer for Actionscript that extends to the length of your whole movie. Anything that is defined on this layer will be accessible globally throughout the whole movie.

Works like a charm for what you are trying to do.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 23, 2009 Jul 23, 2009

As I posted above! I have tried it but for some reason the varibles still don't transferred to the text boxes on the second frame.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 23, 2009 Jul 23, 2009

Accidentally double posted. See the following post.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 23, 2009 Jul 23, 2009

Download and review my attached Fla file. The variable is defined on the first frame. It can be accessed from every other frame in the movie that the "Actionscript" layer extends to.

Enjoy.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 23, 2009 Jul 23, 2009
LATEST

I have now been able to get it working.

Edit:

I should have said that I was using a pc because your files won't open for me in either CS3 nor CS4.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines