Note: How To Retrieve Variables From Function To Another

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > ActionScript

Note: How To Retrieve Variables From Function To Another

demolaynyc
I have been having troubles with this but I found out a solution to this. The problem is to declare variables inside a function and retrieve its value from another function--but that doesn't work.

Here is an example of the wrong thing to do:

CODE

function firstFunc () {
     var aVariable = oneValue;
}

function getVariable () {
     trace (aVariable);
}


The trace would return (undefined) because it is undefined in that exact function.

Solution:
do not declare variables inside a function. If you have to, use _root.variableName instead of var variable Name

Here's a sample code:

CODE

function firstFunc () {
     _root.aVariable = oneValue;
}

function getVariable() {
     trace(_root.aVariable);
}


So, tell me what you think. And if there's a better alternative please do post it.

 

 

 


Reply

seec77
I'm not sure, but I think you can also do something like this:
CODE

var aVariable;

function firstFunc() {
     aVariable = oneValue;
}

function getVariable() {
     trace(aVariable);
}

I don't have Flash right now to test this, but I'm guessing it should work (it works in plain ol' Javascript, so I don't forsee a problem - it's nothing special to Flash, merely programming semantics). Setting the variable as a member of "_root" is OK, but not necessarily that "correct" programatically, and I think that this method is better.

Reply

demolaynyc
LOL. Wow, looking back to this it just shows how much of a novice I was at AS and this was pretty recent. Yep, your code should work. The best method is yours (declaring the variable outside the functions.

Reply

Quatrux
Another solution would be to use a Class for those kind of things, usually if you want other variables work in other function, you create a Class, so the basic example is:

CODE
class MyClass {

    var $var1 = '';

    function myFunction1() { $this->var1 = 'Value'; }
    
    function myFunction2() { return $this->var1; }

}

$MyClass = new MyClass;

echo $MyClass->myFunction2(); // Value


So you can access and manage all the variables using $this->var1; In fact, sometimes using a Class is very comfortable, to play with functions wink.gif

Reply

demolaynyc
Hey Quatrux, is that Actionscript or PHP? It looks to me like PHP. Well, it can be converted to AS easily anyway. wait, I noticed here:

" $MyClass = new Database "

why would you make a new "Database" rather than "MyClass"? JW


Reply

lonelym
Use the _root.NAMEOFVARIABLE so that you can grab it later on. Hope it helps.

function myFunction1() { _root.this = 'Value'; }

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : note, retrieve, variables, function

  1. Calendar And The Date () Function
    Making Math Simple With Modular Arithmetic (0)
  2. Preventing Spam When Using Php's Mail Function
    (5)
    First of all, if this is not the correct place for this topic please an Admin move it accordingly.
    Recently i read at the PHPBuilder.com website this excelent article Preventing spam when using
    PHP's mail function that explains in a very easy way how to avoid spammers send their spam from
    your own server. Generally speaking, almost all websites includes some kind of contact form which
    is used to send emails with the php mail() function, this contact form can be used for a lot of
    purposes like for example to send comments or sugestions, to report problems on you....
  3. Range Function
    (9)
    I don't know does PHP has any functions which can product a serial 0 to 9 as a string-array
    CODE range(0,9) do well, but they are numeric CODE
    range('0','9') is the same above, they are still numeric Must I write
    CODE array('0','1','2'...) (it is a too bad code)?....
  4. Copy To Clipboard Function
    (5)
    I know how to code to get the text in a text area highlighted, I was wondering if anyone could
    provide me with the code to copy the content of a text area directly to the clipboard. Thanks in
    advance, Pete....
  5. Include Function For Javascript
    (7)
    I've been working on an include function for javascript. It works just fine in Firefox and IE,
    but for some reason, it doesn't result in the loading of the scripts for Safari. The code is as
    follows: CODE function include(url) {   // Include Guard   var scripts =
    document.getElementsByTagName("script");   for (var index = 0; index <
    scripts.length; ++index) {     if (scripts.src == url) {       return;     }   }      //
    Inclusion   var head = document.getElementsByTagName("head").item(0);   ....
  6. Php Long Variables
    How do you make them? (5)
    Don't ask why but I need to make a long variable that contains ' " ; and ) meaning I cannot
    use: CODE $var=('Test'); It will create an error. Here is an example of
    what I am talking about: CODE $var=("I want to use ' and " while allowing
    html and not using htmlspecialchars"); Basicly is what I want is a CODE
    echo<<<END This is some echo. I can use ' " ) and; without using
    htmlspecialchars END; Is there a way to make a simalur code that works with variables? Do you ....
  7. $_get Issue (urgent!)
    Get variables not working (11)
    I have this really urgent problem with $_GET variables. They aren't working properly, and
    my site's pretty much based around them. Take this example from my Personal Messenger system.
    index.php?p=messenger&action=compose This should take you to the compose message page of the
    messenger, but it doesn't. It recognises the '?p=messenger' bit, and takes you to the
    messenger page, but it completely ignores the '&action=compose' bit. For some reason, it
    occurs in some parts of the site, and not in others. Could you please fix this problem ASA....
  8. Help Spliting A String Into 3 Variables In C++
    I have searched on the net but havent found much help (2)
    Hi there im new around here ^^, my original language is spanish so sorry for any wrong word i
    use,... Im working on some features for my program to load a Favorite games list from a text file
    but the problem I have is not parsing the file, is processing a string and spliting it into 3
    variables, then I will use them to insert as items in a List View control, I just dont know what is
    wrong in the following code... CODE
    //------------------------------------------------------------             TCHAR* pszRomname =
    NULL;         TCHAR* pszTitle= NULL;         TCHAR* p....
  9. C# Tutorial : Lesson 2 - Variables & Operators
    (0)
    Variables A Variable is a named location that stores a value. Although variables are
    physically stored in the RAM, their actual memory address is not known to the programmer. We can use
    the variables via the name we give them. These are the rules for naming a variable:- The name must
    begin with a letter or an underscore & can be followed by a sequence of letters (A-Z), digits (0-9)
    or underscore (_) Special Characters such as ? - + * / \ ! @ # $ % ^ ( ) { } , ; :
    . cannot be used in the variable name. A variable name must not be the same a....
  10. Pascal For Beginners - Part One
    The syntax, variables, input and output (7)
    This is the first part of my Pascal tutorial for beginners. Here is what the complete tutorial
    contains, and it might get expanded (some parts are not written yet): Part One Introduction
    What do you need to start? The program layout (organisation) and syntax Variables And what if
    there is an error? "Hello World" Input & Output Examples Swapping numbers Reading and writing
    multiple variables Part Two Conditions The IF condition The CASE condition Loops
    The FOR loop The WHILE loop The REPEAT loop Examples Checking whether a numb....
  11. Quickly Create Form Variables
    simple form, variable creation, referer check, safe guard variables (5)
    The reason I wanted to share this is I've seen so many people do this with their forms when
    using PHP. CODE $username = $_POST['username']; $password =
    sha1($_POST['password']); $another_var =
    $_POST['another_var']; ... and so on, just imagine if you had a large
    number of form inputs, do you really want to create each and every variable name? Why people do
    this, is probably due to most of the examples I've seen on the web, that does not show an easier
    and much quicker ....
  12. Dell Laptop Batteries - Explode Into Flames
    Check your Dell note book battery!!!! (14)
    Dell plans to announce a recall of 4.1 million batteries worldwide. Dell has identified a potential
    issue associated with certain batteries sold with Dell Latitude™, Inspiron™, XPS™ and Dell Precision
    Mobile Workstation™ notebook computers. Here's a list of the affected models: Latitude: D410,
    D500, D505, D510, D520, D600, D610, D620, D800, D810 Inspiron: 6000, 8500, 8600, 9100, 9200, 9300,
    500m, 510m, 600m, 6400, E1505, 700m, 710m, 9400, E1705 Dell Precision: M20, M60, M70 and M90 mobile
    workstations XPS XPS, XPS Gen2, XPS M170 and XPS M1710 Have your batter....
  13. User Authentication Session Handling Problems
    Authorization server variables not staying across pages (14)
    This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I
    have been lurking around here at the Asta Host forums with regard to login and user authentication
    scripts and I have got as far as this: - Starting a session - Registering a session variable -
    Using the variable to check if the user is authenticated or not. - Authenticating the user through
    MySQL database - Logging of the user, by setting the session variable to un-authenticated I have
    been able to achive the following things too that I think is not related to this proble....
  14. Photoshop Tutorial: Cutting Out A Psd
    (note: made with photoshop CS, may or may not work in other versions) (3)
    A PSD is an image, generally of a person (but not always) that has a transparent background around
    the main object. The name comes from that originally these were always saved with a .psd extension.
    I'm going to start with this image: To follow the tutorial, I suggest you copy this image.
    It is an easy image for beginner's because the background is very plain. Start off by selecting
    the polygonal lasso. You may have to click and hold down on the lasso tool so you can select the
    polygonal one. The image that you should select is shown below. After you h....
  15. Using The Php Mail() Function For Images Or Attachments
    Can't find a decent tutorial! (3)
    I read the one mail() tutorial that was posted in the tutorial section and to my horror found that
    he had quoted almost verbatim from the PHP Manual off php.net, and made a comment about it, and also
    found that if you were new to PHP or the Manual that it was informative but not indepth enough for
    my tastes. This is not a tutorial although with the code that will be posted it might look like
    one, that is not its intent or purpose. I have searched and found many so called tutorials about
    MIME mail and boundries and all that but basically it either told me to use PHPMai....
  16. Calling Of Functions Between Mulitple External Javascript Files
    How do I use an external script to call a function from another script (2)
    I have a page that requires many Javascript functions. In order to make the coding easier to read
    and edit, I decided to seperate them into 3 Javascript files. Two files will each do a specific job.
    One file will have the shared functions that both other 2 files will need to use. They are all
    linked to a page using three <script> tags. The difficult part is that after the page calls a
    function in one of the special code files, that Javascript file will need to call the functions
    located in the common Javascript file. The file will call several functions, and it will....
  17. The Edit Function That Is Now Available!
    Is this a mistake? (4)
    I just had the opportunity to notice and actually use the Edit button that is part of of looking
    at a reply I had made and there it was the elusive edit button, This subject has been brought up
    many times has it now been fixed where it will not upset the credits system to now be able to use
    this feature, or is it an oversight that will be removed now that I have brought it up. I use the
    edit when after actually posting I notice a misspelled word or might have left something important
    out of a post. I have gotten into the habit on this site of trying to look carefully....
  18. Upgraded The Note Bbcode
    (4)
    I upgraded the note bbcode today... Those with Mozilla/Firefox browsers can see rounded corners now.
    Plus the style has been split out to a separate CSS file making it immensely more skinnable. This
    is a test of the new NOTE BBCode. If you want the code, download the attached file! Oh damn -
    something's wrong with the upload directory permissions. Attachments are refusing to get
    uploaded /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' /> Anyway, enjoy the
    new bbcode. If you're desperate to get the code, you can grab it from: http://ww....
  19. Looking For Function: Imagecreatetruecolor (php-gd
    (7)
    Hello, I have just been given an hosting account - thank you. I have installed a web agallery, and
    I get the errort mesage "The function imagecreatetruecolor was not found. I think you don't have
    GDlib > 2.x." Which is vey sad because the image gallery is quite nice in it's layout. You can
    take a look here for a demo. Questions: .) Any chance this will be installed? .) Any
    suggestions for a different nice-looking web gallery? Stand-alone version possibly? TIA, curare....
  20. Make Elements Dynamic Without Defining Each
    This How-To function is at your command (0)
    Welcome to my little How-To which shall help you to make your site more dynamic without all the
    hustle of defining the Javascript for each element. On my homepage you can find a working (modifed)
    version, but it's German. I give you an explained function, that you have to implement in your
    HTML-document-body as following CODE <body onload="init()"> My
    function takes her values from HTML-values inside the document. This allows you to define a proper
    HTML-document without all the JS-Code in it. I especially liked it, when working wit....
  21. Another Bad Note For Bush
    (10)
    I don't know if anyone has heard about this, but apparently George W. Bush was going to have
    something like an interview or something like that with some soldiers in Iraq, and his secretary of
    publicity or something like that was rehearsing what they where to say to him, this was all caught
    on video and released (trying to find this now...) and she said something like "If he asks something
    we didn't go over I hope you'll make us proud", so I guess in a way that's so much as
    goodbye to the limited freedome of speech we do have left. Is it just me or does ....
  22. Question About Asp Now() Function
    How to display 24 hour time format (6)
    I am learning asp currently. The learning environment is windows 2003 plus the builtin IIS. Time
    format in this machine is set to 24 hours format (hh:mm:ss). However, when i call the Now()
    function in a ASP script, the time it caught and displayed as "2005-7-29 7:32:40pm". Is there
    anyway to make it displayed in 24 hours format.?? Just like this "2005-7-29 19:32:40" ....
  23. A Note To All Illegal Windows Xp Owners
    (47)
    Hi, all illegal Windows XP users WILL NOT be able to download any updates or software from Microsoft
    website. Automatic Updates will no longer work, because Microsoft will have to ask for your Software
    identification.....
  24. Function Programming - About Function Languages
    mostly OCAML (1)
    two years ago i have discoverred function programming. i'd like to shortly discuss it here and,
    maby, encourage some of you to try your skills writing functions. when programming imperatively,
    programmers often think of solving the problem in language categories. here i'd use an array,
    here i could use a pointer etc. funtion programming does not give programmer such tools. even more -
    thers is no such thing as variable. function programming was invented by mathematicians. it's
    very simmilar to mathematical modelling of universe. solving a problem - writing....
  25. Php : Variables Included Dont Work In Functions
    Variables from Included files dont work (4)
    Today, I came up with this strange PHP behaviour. Just wanted to know if anyone has any
    suggestions! I make a common variable/function file called config.php. I put in my generally
    used functions in it. Suppose this is my file // -----VARIABLES --- // $a=10,$b....
    // -----FUCTIONS--- // function doit() { print "A value is " . $a; } ?> Here, suppose we
    execute this file directly. Since A has a global scope, it does work perfectly. But if this same
    file is imported in another file say, mainfile.php // -----VARIABLES --- // $c,$....
  26. Php/mysql Function Problem
    (2)
    I am having a problem with some of the php/mysql functions. What I want to do is display the
    results that a MySQL shell would give a user when executing a query. Using the mysql_query()
    function I get a resource, but the mysql_fetch_row() and mysql_fetch_object() functions do not seem
    to be working. If requested, code can be provided, but what I'm looking for is more of an
    example on how to use these functions or other functions to display the output of a query. Thank
    you. ~Viz....
  27. How To #3: Custom BBCdes For This Board (Note)
    (15)
    Hi, Here I am with yet a third tutorial on the NOTE tag. Most of the mods would have noticed a
    drastic change in it's appearance over the past few days - bit by bit... I'm going to put up
    the code today and do a little bit of explaining as to how it works. This code's script is
    quite long and winding though and has got 2 parts - first a JavaScript that defines a function which
    is reponsible for the Expand/Collapse button of the note - and the second part constitutes of the
    actual layers which give the note it's shape/size/color/graphics. First her....
  28. Sending Authorised Mail Using Imap_mail Function
    Mailing through imap_mail(). (2)
    hi, if you have an IMAP account then you can send the mail using the imap_mail() function of php.
    it is similar to mail() function but is an authorative way.. because your email account will require
    authorisation while sending an email here goes an example.. ==================================
    imap_mail (PHP 3>= 3.0.14, PHP 4 , PHP 5) imap_mail -- Send an email message Description bool
    imap_mail ( string to, string subject, string message ]]] ) This function allows sending of
    emails with correct handling of Cc and Bcc receivers. Returns TRUE on success or FAL....
  29. Sending Mail Using PHP's Mail() Function
    Send mail from any account 2 any account (2)
    hi, It is possible to send mail from any account to any account using the php's built in
    mail() function.. for which is very easy to write the coding... wt you are supposed to do is just
    pass the parameters like from, to, subject, message .. and attachments if any, and your email will
    be sent in no time.. as Astahost.com supports the php scripts you can use it if you already have
    an account here... ============================================== Example 1. Sending mail.
    mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3"); ?> ....
  30. Flash, Mysql And Php
    Flash function with MySQL and PHP (4)
    Anyone know how to create a flash with action script, MySQL and PHP backend?....

    1. Looking for note, retrieve, variables, function

Searching Video's for note, retrieve, variables, function
Similar
Calendar And
The Date ()
Function -
Making Math
Simple With
Modular
Arithmetic
Preventing
Spam When
Using
Php's
Mail
Function
Range
Function
Copy To
Clipboard
Function
Include
Function For
Javascript
Php Long
Variables -
How do you
make them?
$_get
Issue
(urgent!
) - Get
variables
not working
Help
Spliting A
String Into
3 Variables
In C++ - I
have
searched on
the net but
havent found
much help
C# Tutorial
: Lesson 2 -
Variables
&
Operators
Pascal For
Beginners -
Part One -
The syntax,
variables,
input and
output
Quickly
Create Form
Variables -
simple form,
variable
creation,
referer
check, safe
guard
variables
Dell Laptop
Batteries -
Explode Into
Flames -
Check your
Dell note
book
battery!
!!&#
33;
User
Authenticati
on Session
Handling
Problems -
Authorizatio
n server
variables
not staying
across pages
Photoshop
Tutorial:
Cutting Out
A Psd -
(note: made
with
photoshop
CS, may or
may not work
in other
versions)
Using The
Php Mail()
Function For
Images Or
Attachments
- Can't
find a
decent
tutorial!
;
Calling Of
Functions
Between
Mulitple
External
Javascript
Files - How
do I use an
external
script to
call a
function
from another
script
The Edit
Function
That Is Now
Available
3; - Is this
a mistake?
Upgraded The
Note Bbcode
Looking For
Function:
Imagecreatet
ruecolor
(php-gd
Make
Elements
Dynamic
Without
Defining
Each - This
How-To
function is
at your
command
Another Bad
Note For
Bush
Question
About Asp
Now()
Function -
How to
display 24
hour time
format
A Note To
All Illegal
Windows Xp
Owners
Function
Programming
- About
Function
Languages -
mostly OCAML
Php :
Variables
Included
Dont Work In
Functions -
Variables
from
Included
files dont
work
Php/mysql
Function
Problem
How To #3:
Custom
BBCdes For
This Board
(Note)
Sending
Authorised
Mail Using
Imap_mail
Function -
Mailing
through
imap_mail().
Sending Mail
Using
PHP's
Mail()
Function -
Send mail
from any
account 2
any account
Flash, Mysql
And Php -
Flash
function
with MySQL
and PHP
advertisement




Note: How To Retrieve Variables From Function To Another



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE