A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: global code problem

  1. #1
    Senior Member
    Join Date
    Jun 2006
    Posts
    100

    global code problem

    I'm doing a key pad to teach text messageing. I was given this code and it works fine until I add more then 4 buttons. Then the count stops working right and I'm not able to add any of the letters after the first one.
    I'm assuming it has to do something with the _global code, but I don't know which one to move or replace.



    10 buttons on their own layer all on frame 7, main time line.

    //On main time line, frame 7

    //_root.button1.onEnterFrame = function(){
    _root.button1.onRelease = function(){
    _global.count = 0;
    this.gotoAndStop(this._currentframe +1);
    }
    //}



    In side of button, on Layer 1, frame 1 (I have this on each of the 10 MCbuttons):

    _global.count = 0;
    this.onEnterFrame = function(){
    _global.count++;
    trace(_global.count);
    }

    //layer 2, for letters D (plus three more for the letters E, F, 2):
    this.pressIt1.onEnterFrame = function(){
    if(_global.count >= 10){
    //change your text field - something like
    _root.yourTextField = _root.yourTextField + "D";
    //frame one - b for frame 2 and c for frame 3
    _global.count = 0;
    this._parent.gotoAndStop(1);
    }
    }

  2. #2
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    What version of flash are you using?

    MX likes _global, F8 likes _root instead.

  3. #3
    Senior Member
    Join Date
    Jun 2006
    Posts
    100
    Flash MX pro 2004

  4. #4
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Try changing your _global to _root. I've had this problem before. Variables are stored in the controller in the flashplayer, and for some reason MX likes _global. Newer versions don't for some reason. Using _root instead usually fixes it.

  5. #5
    Senior Member
    Join Date
    Jun 2006
    Posts
    100
    Wow that is weird, with the change its working. So does that mean if I upgrade to 8 I'll have to change it back to _global?
    Thank you for the help!

  6. #6
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    No, flash 8 likes _root. It's only MX that prefers _global.

    And it is weird. It took me weeks to figure out the connection there, cause it's not documented. In fact, you can find very little about using _global at all.

  7. #7
    Senior Member
    Join Date
    Jun 2006
    Posts
    100
    I have a book on "flash mx actionscripting advanced training from the source" He has a whole section on global use but he said global needs to be stated on the main time line then it can be called any where in the project....that's why I was wondering if stating a _global call on every button was causing the problem. I just don't know enough about scripting to make changes like that.

  8. #8
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Yes, and he's right. Up to about 4 different globals. After that, it seems to stop reading them, where using _root always seems to work.

  9. #9
    Senior Member
    Join Date
    Jun 2006
    Posts
    100
    thanks for the heads up. I'll write that in my book.
    Thanks.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center