A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: F*cking Variables

  1. #1
    Junior Member
    Join Date
    Aug 2002
    Posts
    23

    F*cking Variables

    Hi, I've got a movie which displays thumbnails of different projects.

    I've a container (mc) with different pictures in every frame.
    And using this script to place them in a grid:
    if (n<e) {
    duplicateMovieClip(bilder, ["bilder"+n], n);
    if (n == 12 || n == 24 || n == 36 || n == 48 || n == 60 || n == 72) {
    y++;
    }
    setProperty(["bilder"+n], _y, 50*y);
    setProperty(["bilder"+n], _alpha, -10*n);
    setProperty(["bilder"+n], _x, 50*(n-12*y));
    }
    n++

    And in that mc (bilder), i've set so that it goes to the next frame for each "n++".

    Which works good, except that I also want to be able to sort them in different ways.

    I started to make a dynamic list with the vars:
    o1=14
    o2=92
    and so on...

    After that I made a different code which are going to sort them in a new order, with the code:

    if (np<e) {
    if (np == 12 || np == 24 || np == 36 || np == 48 || np == 60 || np == 72) {
    yp++;
    }

    setProperty(["bilder"+["o"+np], _y, 50*yp);
    setProperty(["bilder"+["o"+np], _x, 50*(np-12*yp));
    }
    np++

    where ["o"+np] should be the variable o1 for example and set "bilder14" to be first in the list.


    But it doesn't work... which is driving me insane!!!!
    Can anyone solve this????

    is it possible to use multiple text and variables in "setProperty"?

    Or should this be solved in a totally different way?

  2. #2
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    For one thing, you're missing a closing ] bracket.

  3. #3
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    hi, thanks for replying.
    The actual script works, just forgot one right now.

    the thing is that it works if I don't use the variables in "setProperty".

    Any ideas?

  4. #4
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    What Flash version are you publishing for? Setproperty has been deprecated, hasn't it? Maybe you're publishing in Flash 7 and it's not allowing that command.
    Trying publishing in Flash 5 and see if it makes a diff.

  5. #5
    Junior Member
    Join Date
    Feb 2004
    Location
    Alaska, USA
    Posts
    5
    setProperty works in flash player 7

  6. #6
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Hi, thanks for the tips.

    but the scripts works really good except for the fact that I want to create a variable ("o1") so that setProperty uses it, by using a letter and a variable which increases by 1 to use "o2" next time.

    example:

    this script to works:

    L=5
    setProperty(["clip"+L], _y, 10*L);
    L++

    which should place the MC "clip5" to 50 in _y.
    and MC "clip6" to 60 in y.

    what doesn't work is if I want the variable H5
    which could H5=85 to act as an extension on "clip".
    like clip85

    H40=50
    L=40
    setProperty(["clip"+["H"+L], _y, 10*L);
    L++

    action:
    clip50 to be placed in _y 400

    Does this make sense?
    I can hardly understand myself...

    I'm trying to place a series of MC's in different orders by using a variable serie to place without having to write 100 lines of setProperty...

    I can send the fla-file if you think that you could help me!

    Cheers

  7. #7
    Junior Member
    Join Date
    Feb 2004
    Posts
    19
    You need to use the eval(). Dont ask me why but you do. Something like Flash doesnt appreciate that youre actually refering to a mc until you do the eval.

    Code should look something like this:

    o = "name" + L;
    newName = eval(o)
    changedItem = setProperty(newName,,,,,)

    HTH

  8. #8
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    I can hardly understand myself...
    So do I…
    I can send the fla-file if you think that you could help me!
    Along with more clear explanations.

    You need to use the eval(). Dont ask me why but you do.
    Wow! What will happen if ask why should I need it. And may I show you that it's possible to do things without eval()?
    Last edited by sergwiz; 02-28-2004 at 11:00 AM.

  9. #9
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Hey, It worked!
    thank you so much!

    now I just have to deal with some other code issues. but compared to this it will be smooth...

  10. #10
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Hi, sergwiz.
    I don't quite understand you, but sure if you know a way around eval().
    please...

    But it actually works now..
    with just 2 lines of extra coding...

    /frenne

  11. #11
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    I would help you if you could explain to me what you are trying to do. I look at this code and I don't understand it.
    if (n<e) {
    duplicateMovieClip(bilder, ["bilder"+n], n);
    if (n == 12 || n == 24 || n == 36 || n == 48 || n == 60 || n == 72) {
    y++;
    }
    setProperty(["bilder"+n], _y, 50*y);
    setProperty(["bilder"+n], _alpha, -10*n);
    setProperty(["bilder"+n], _x, 50*(n-12*y));
    }
    n++

    What is it "e"?
    What is it bilder? Is it a name of MovieClip? If yes, then it should be this way:
    duplicateMovieClip("bilder", "bilder"+n, n);
    this["bilder"+n]._y = 50*y;
    this["bilder"+n]._x = 50*(n-12*y)

    How can work this setProperty(["bilder"+n], _alpha, -10*n);, if n>=10?
    It would be better if you show your fla file.

  12. #12
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Hi, its probably easier if I explain to you in plain text.
    This section of the movie is a portfolio with around 100 projects which should easily be upgraded and can be sorted in different ways provided with dynamic text files.

    By accomplishing this I've created a MC which in the first frame sets different variables to certain values, like "e" which is the total framecount of the movieclip "bilder". that mc contains thumbs of every project which should be published.
    So, what the code which you quoted does is:
    duplicates the mc "bilder" and places it in a grid with 12 thumbs horizontially and a couple of rows vertically depending on the framecount (e).
    each movieclip get an offset value in alpha, like -220. So that I can in the next loop fade all clips in a "flow".
    in the next loop I want to sort the text in different patterns, which is provided by a external text.
    And that works with eval().

    Do you understand me?
    I'm from Sweden, I usually speak swedish. Please be patient

    you wrote:
    What is it bilder? Is it a name of MovieClip? If yes, then it should be this way:
    duplicateMovieClip("bilder", "bilder"+n, n);
    this["bilder"+n]._y = 50*y;
    this["bilder"+n]._x = 50*(n-12*y)
    the script I have now works, is it better to code it like you suggested it?
    is it quicker or has any other advantages?

  13. #13
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    I recommend staying away from SetProperty unless you are publishing for Flash 4. It's the old way of doing things. If you want to access clip properties AND also access variables inside the clip, it's way simpler to use dot notation.

    Example:

    _root["clip"+L].myvar = 0;

    or

    _root["clip"+L]._alpha = 50;


    As for what is eval(), eval means "evaluate by name" and is the old Flash 4 way that has now been replaced by just using these: [ ]

    So, eval("bilder"+L) is the same as ["bilder"+L]

  14. #14
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    by the way, I just wanted to add that what really messed me up when i learned to use dot notation and [ ] was that you're not supposed to use a dot in certain places where logically it looks like there should be.

    In the example I showed above, note that there is no period between "_root" and the variable to be evaluated as a clip name "["clip"+L]".

    I know that makes no sense, but that's how Flash likes it. This for example would NOT be accepted:

    _root.["clip"+L].myvar = 0;


    ~Ray

  15. #15
    Junior Member
    Join Date
    Aug 2002
    Posts
    23
    Hi, I have recoded my movie, and it is actually smoother since I swapped the setProperty.
    Thanks!
    but still the code doesn't work without eval().
    could be since I need to form a variable by using a letter and a variable. I don't really know why...
    But hey, it works. Thanks all, I would really be stuck otherwise

    /Henrik

  16. #16
    Junior Member
    Join Date
    Feb 2004
    Posts
    19
    Ray Beez,

    Cheers for the info about eval() and the new dot notation replacing setProperty. Will start using it in my next flash project - ah the joys of learning new code

  17. #17
    Junior Member
    Join Date
    May 2002
    Location
    Nice/france
    Posts
    9

    thank you so much

    It help me to much. It made 2 days I am on my Mysql links project. and it was the last fence.

    Thanks
    The Xbox H4cker on Nice/france
    XecuterII

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