Is there a way to + number in a shared object?

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default Is there a way to + number in a shared object?

    If you have a textfield like a scoreboard with the number 10 you can use:

    btn1.onPress = function() {
    _root.scoreboard += 5;
    };

    to add 10 points to the scoreboard.

    Is there a way to do the same if you have a shared object?

    Thanks.

    /Andy


    - = v i p e r = - webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Flash Shared Object
      Hi There, Is it possible that edit or delete specific data from .fso file. I know we can delete all of data from clear(); but can we view .fso...
    2. Shared Object
      Hi there all, Just a quick question on the uses of the Shared Object to store data locally, if I was to save a series of the same field locally...
    3. Shared object limits???
      Hi, I?m using the whiteboard component in a virtual classroom application. The drawings on the whiteboard are stored in one shared object. After...
    4. Shared Object Definition
      I have a class (UserType) that is used in multiple web services. How do I get my client and/or web services to recognize it as the same class?...
    5. Shared object name??
      Is there a way to make flash name the shared object .sol file? I whant it to create a new file instead of overwright the existing one. Like: my_so =...
  3. #2

    Default Re: Is there a way to + number in a shared object?

    "- = v i p e r = -" [email]webforumsuser@macromedia.com[/email] wrote:
    > If you have a textfield like a scoreboard with the number 10 you can use:
    >
    > btn1.onPress = function() {
    > _root.scoreboard += 5;
    > };
    >
    > to add 10 points to the scoreboard.
    >
    > Is there a way to do the same if you have a shared object?
    >
    > Thanks.
    >
    > /Andy
    >
    yes, same sort of thing

    _global.sharedObjRef = SharedObject.getLocal("scoreboarddata");
    btn1.onPress = function()
    {
    _global.sharedObjRef.data.score += 5;
    _global.sharedObjRef.flush();
    }


    --
    MOLOKO
    ------------------------------------------------
    ::remove _underwear_ to reply::
    'God saves but Buddha makes incremental backups'
    ------------------------------------------------
    GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
    VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
    see [url]www.geekcode.com[/url] to translate the above!
    MOLOKO Guest

  4. #3

    Default Re: Is there a way to + number in a shared object?

    sure.

    Z = SharedObject.getLocal("myFile");
    Z.data.scoreboard = 0;
    .....
    Z.data.scoreboard++;

    --

    Pierre Alain

    [email]pie@lifnet.com[/email]


    "- = v i p e r = -" <webforumsuser@macromedia.com> a écrit dans le message
    de news:bu2von$jp6$1@forums.macromedia.com...
    > If you have a textfield like a scoreboard with the number 10 you can use:
    >
    > btn1.onPress = function() {
    > _root.scoreboard += 5;
    > };
    >
    > to add 10 points to the scoreboard.
    >
    > Is there a way to do the same if you have a shared object?
    >
    > Thanks.
    >
    > /Andy
    >
    >

    PierreAlain Guest

  5. #4

    Default Re: Is there a way to + number in a shared object?

    by shared object, do you mean one imported from a shared library, or a 'shared object' meaning a flash object that is communicated with through some kind of inter-movie communication? if the object is imported from a shared library by using attachMovie or something like that, you just have to know which ID you used as an arg...that would allow you to create the correct path to the object where you can increment its internal values (i *think* this is how it works).




    sneakyimp webforumsuser@macromedia.com Guest

  6. #5

    Default Re: Is there a way to + number in a shared object?

    yes, same sort of thing

    _global.sharedObjRef = SharedObject.getLocal("scoreboarddata");
    btn1.onPress = function()
    {
    _global.sharedObjRef.data.score += 5;
    _global.sharedObjRef.flush();
    }


    Thanks for the reply!

    I have a flashcom server. I store all shared objects there. If I have a shared object with the number
    10 and try to use this code, all it does is wright 105 to the shared object. Why? I whant the shared object to say 15 not 105.

    Please help im going nuts!!

    /Andy


    - = v i p e r = - webforumsuser@macromedia.com Guest

  7. #6

    Default Re: Is there a way to + number in a shared object?

    "- = v i p e r = -" [email]webforumsuser@macromedia.com[/email] wrote:
    > yes, same sort of thing
    >
    > _global.sharedObjRef = SharedObject.getLocal("scoreboarddata");
    > btn1.onPress = function()
    > {
    > _global.sharedObjRef.data.score += 5;
    > _global.sharedObjRef.flush();
    > }
    >
    >
    > Thanks for the reply!
    >
    > I have a flashcom server. I store all shared objects there. If I have a shared object with the number
    > 10 and try to use this code, all it does is wright 105 to the shared object. Why? I whant the shared object to say 15 not 105.
    >
    > Please help im going nuts!!
    >
    > /Andy
    >
    a-ha - probably because one of them is a string, not a number, so it's
    concatenating them instead of adding (in AS the '+' operator means both
    'concatenate' and 'add'. Therefore this code:
    var numa = "10";
    var numb = "5";
    trace(numa + numb); //would return '105'

    Although flash should try an convert strings to numbers when required,
    it doesn't. To ensure your variable actually contains a number, multiply
    it by one:
    var numa = "10" * 1;
    var numb = "5" * 1;
    trace(numa + numb); //now returns '15'


    --
    MOLOKO
    ------------------------------------------------
    ::remove _underwear_ to reply::
    'God saves but Buddha makes incremental backups'
    ------------------------------------------------
    GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
    VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
    see [url]www.geekcode.com[/url] to translate the above!
    MOLOKO Guest

  8. #7

    Default Re: Is there a way to + number in a shared object?

    oops... replied to wrong post. try again!
    "- = v i p e r = -" [email]webforumsuser@macromedia.com[/email] wrote:>
    > Thanks for the reply!
    >
    > I have a flashcom server. I store all shared objects there. If I have a shared object with the number
    > 10 and try to use this code, all it does is wright 105 to the shared object. Why? I whant the shared object to say 15 not 105.
    a-ha - probably because one of them is a string, not a number, so it's
    concatenating them instead of adding (in AS the '+' operator means both
    'concatenate' and 'add'. Therefore this code:
    var numa = "10";
    var numb = "5";
    trace(numa + numb); //would return '105'

    Although flash should try an convert strings to numbers when required,
    it doesn't. To ensure your variable actually contains a number, multiply
    it by one:
    var numa = "10" * 1;
    var numb = "5" * 1;
    trace(numa + numb); //now returns '15'


    --
    MOLOKO
    ------------------------------------------------
    ::remove _underwear_ to reply::
    'God saves but Buddha makes incremental backups'
    ------------------------------------------------
    GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
    VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
    see [url]www.geekcode.com[/url] to translate the above!
    MOLOKO Guest

  9. #8

    Default Re: Is there a way to + number in a shared object?

    You are the man!

    That thing with *1 to make it a number and not a string! Great stuff!!

    Thanks!!!

    /Andy


    - = v i p e r = - webforumsuser@macromedia.com Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139