Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-10-2009, 10:08 PM   #1
BastianR
Registered User
 
Join Date: Aug 2009
Location: Plymouth, UK
Posts: 26
Default Accessing variables defined in a function

Hi all,
I have been playing around with combining flash and PHP/Mysql for some time now, mainly sending one flash variable to a PHP file and then retrieving a result and turning it back into a different flash variable. My problem is i've got to the stage where I need to access these variables from other functions. Now I think I need to find some way of defining them outside of the function, maybe using global vars? Well i'm not gonna pretend I know anything about it. The two functions from which I access my PHP variables is as follows:
ActionScript Code:
function btnDown(event:MouseEvent):void { var variables:URLVariables = new URLVariables(); var varSend:URLRequest = new URLRequest("http://localhost/test.php"); varSend.method = URLRequestMethod.POST; varSend.data = variables; var varLoader:URLLoader = new URLLoader; varLoader.dataFormat = URLLoaderDataFormat.VARIABLES; varLoader.addEventListener(Event.COMPLETE, completeHandler); variables.uname = Username_text.text; variables.sendRequest = "parse";    varLoader.load(varSend);                 function completeHandler(event:Event):void{         var phpVar1 = event.target.data.var1;
So I need a way to access the phpVar1 variable in a totally seperate function and i'm not really sure how
Any suggestions would be much appreciated, thanks
BastianR is offline   Reply With Quote
Old 08-10-2009, 10:15 PM   #2
Poskusin
Registered User
 
Join Date: Jul 2009
Posts: 20
Default

I'm no genius when it comes to AS, but I think your only two options are to either make the var global by defining it outside your functions or passing it to another function (eg)

function firstFunction():void
{
var someVariable:Number = 10;
secondFunction(someVariable);
}

function secondFunction(passedVariable:Number):void
{
trace (passedVariable);
}

Hope that helps?
Poskusin is offline   Reply With Quote
Old 08-10-2009, 11:42 PM   #3
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

define it outside the function. Variables declared inside functions are local variables and don't exist outside of that function.
__________________
(6)
senocular is offline   Reply With Quote
Old 08-11-2009, 06:17 AM   #4
BastianR
Registered User
 
Join Date: Aug 2009
Location: Plymouth, UK
Posts: 26
Default

Thanks for the replies.
What exactly would I define the variable as? Although it's a number defining it as one returns Nan, is there a special term for defining variables coming from PHP?
BastianR is offline   Reply With Quote
Old 08-11-2009, 07:57 AM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,676
Send a message via Skype™ to henke37
Default

Define it in the class.
henke37 is online now   Reply With Quote
Old 08-12-2009, 07:59 AM   #6
BastianR
Registered User
 
Join Date: Aug 2009
Location: Plymouth, UK
Posts: 26
Default

I've never really bothered using classes yet in AS3, could you give me a little snippet of example code to explain what you mean? thanks
BastianR is offline   Reply With Quote
Old 08-12-2009, 02:20 PM   #7
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,676
Send a message via Skype™ to henke37
Default

ActionScript Code:
package { class SXdwgewd extends Sprite { var tsad; } }
henke37 is online now   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.