Results 1 to 8 of 8

Thread: Calling variables outside of functions in Flash

  1. #1
    Member
    Join Date
    Sep 2007
    Location
    Leeds
    Posts
    166
    Thanks
    4
    Thanked
    5 times in 5 posts
    • Clockwork_Killa's system
      • Motherboard:
      • Asus KFN5-D SLI
      • CPU:
      • Opteron 2212 (2x)
      • Memory:
      • 4 gig Kingston ecc reg in dual channel
      • Storage:
      • 2x Raptor 36gig in raid 0, 1 Raptor X
      • Graphics card(s):
      • Fire GL 3100
      • PSU:
      • Corsair HX620
      • Case:
      • Coolermaster CM Stacker EVO
      • Monitor(s):
      • NEC Multisync 90GX2
      • Internet:
      • BE

    Calling variables outside of functions in Flash

    Does anyone have any idea how to call variables outside of functions in flash? What I mean is, if I set up a variable inside a function and then try to trace that variable outside of the function it will come up undefined, does anyone know how to get round this?

    Just to give an example, if I were to try this:
    Code:
    onLoad = function(){
    myName="bob";
    }
    trace(myName);
    I would get an undefined in the output box.

    There must be a way round this, but I cant figure it out and its driving me absolutely nuts.
    For the record I have tried using root and global variables but the result is the same.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    10
    Thanks
    0
    Thanked
    0 times in 0 posts

    Re: Calling variables outside of functions in Flash

    Not sure how it's done in flash but in vb you can pass a variable into and out of a function by declaring a variable inside the function brackets and then calling it with the variable name in the brackets.

  3. #3
    Member
    Join Date
    Sep 2007
    Location
    Leeds
    Posts
    166
    Thanks
    4
    Thanked
    5 times in 5 posts
    • Clockwork_Killa's system
      • Motherboard:
      • Asus KFN5-D SLI
      • CPU:
      • Opteron 2212 (2x)
      • Memory:
      • 4 gig Kingston ecc reg in dual channel
      • Storage:
      • 2x Raptor 36gig in raid 0, 1 Raptor X
      • Graphics card(s):
      • Fire GL 3100
      • PSU:
      • Corsair HX620
      • Case:
      • Coolermaster CM Stacker EVO
      • Monitor(s):
      • NEC Multisync 90GX2
      • Internet:
      • BE

    Re: Calling variables outside of functions in Flash

    Quote Originally Posted by DazJWood View Post
    Not sure how it's done in flash but in vb you can pass a variable into and out of a function by declaring a variable inside the function brackets and then calling it with the variable name in the brackets.
    Could you give me an example in VB so I can have a look, I have successfully mashed VBscript into action script before so it just might work.

  4. #4
    Senior Member manwithnoname's Avatar
    Join Date
    Dec 2005
    Posts
    1,050
    Thanks
    17
    Thanked
    26 times in 25 posts

    Post Re: Calling variables outside of functions in Flash

    vb would be something like :

    Code:
    dim myName;
    
    Sub sid()
    myName = "bob"
    End Sub
    
    trace(myName)
    If you got any kind of documentation read the section on 'variable scope' if you can find it.

  5. #5
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Calling variables outside of functions in Flash

    Declare the variable in the same scope from where you want to call it external to the function.
    To err is human. To really foul things up ... you need a computer.

  6. #6
    Member
    Join Date
    Sep 2007
    Location
    Leeds
    Posts
    166
    Thanks
    4
    Thanked
    5 times in 5 posts
    • Clockwork_Killa's system
      • Motherboard:
      • Asus KFN5-D SLI
      • CPU:
      • Opteron 2212 (2x)
      • Memory:
      • 4 gig Kingston ecc reg in dual channel
      • Storage:
      • 2x Raptor 36gig in raid 0, 1 Raptor X
      • Graphics card(s):
      • Fire GL 3100
      • PSU:
      • Corsair HX620
      • Case:
      • Coolermaster CM Stacker EVO
      • Monitor(s):
      • NEC Multisync 90GX2
      • Internet:
      • BE

    Re: Calling variables outside of functions in Flash

    Well from what Ive read on scope, I should be able to use a global variable, given that they are accessible globally within any scope, but that doesnt work either. Even if I define a global variable I still cant call it outside of the function. It doesnt make any sense at all and its driving me mad!

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Calling variables outside of functions in Flash

    so:

    Code:
    var myvar:String = "";
    onLoad = function(){
    myvar="bob";
    }
    trace(myvar);
    Doesn't trace 'Bob'? Are you sure the onLoad event is being called?
    To err is human. To really foul things up ... you need a computer.

  8. #8
    Member
    Join Date
    Sep 2007
    Location
    Leeds
    Posts
    166
    Thanks
    4
    Thanked
    5 times in 5 posts
    • Clockwork_Killa's system
      • Motherboard:
      • Asus KFN5-D SLI
      • CPU:
      • Opteron 2212 (2x)
      • Memory:
      • 4 gig Kingston ecc reg in dual channel
      • Storage:
      • 2x Raptor 36gig in raid 0, 1 Raptor X
      • Graphics card(s):
      • Fire GL 3100
      • PSU:
      • Corsair HX620
      • Case:
      • Coolermaster CM Stacker EVO
      • Monitor(s):
      • NEC Multisync 90GX2
      • Internet:
      • BE

    Re: Calling variables outside of functions in Flash

    Ive tried with onLoad and onEnterFrame events but it still wont do it, it really doesnt make sense. The load event is definitely happening because if you put the trace inside the function it traces properly, it just wont access the variable outside the function.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. please urgent help needed with c++ program
    By haelly in forum Welcome to HEXUS!
    Replies: 2
    Last Post: 19-12-2007, 11:02 PM
  2. urgent help with c++ function access
    By haelly in forum Welcome to HEXUS!
    Replies: 1
    Last Post: 17-12-2007, 05:11 PM
  3. Compact Flash Extreme III
    By 03peacheym in forum Retail Therapy and Bargains
    Replies: 17
    Last Post: 11-08-2007, 05:25 PM
  4. Flash Voyager Performance and New Product Update, READ ME!
    By Yellowbeard in forum Solid State Drives (SSD)
    Replies: 0
    Last Post: 21-03-2007, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •