A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 15 of 15
  1. #1
    Junior Member
    Join Date
    May 2002
    Posts
    13

    setProperty problems

    The script is not realizing the value of "menuh"&(counter) (ex: menuh1 = 14). Any idea why?

    This is loaded first:
    // Set up variable to keep track of which menu is being clicked.
    menu_num = "0";
    menuh1 = "14";
    menuh2 = "195";
    menuh3 = "245";
    stop();
    This brings the category UP:
    counter = menu_num;
    while (Number(counter)<3) {
    counter = Number(counter)+1;
    setProperty("/menu"&(counter), _y, getProperty ( "/menu"&(counter), _y )-"menuh"&(counter));
    }
    This brings the category DOWN:
    counter = menu_num;
    while (Number(counter)<3) {
    counter = Number(counter)+1;
    setProperty("/menu"&(counter), _y, getProperty ( "/menu"&(counter), _y )+"menuh"&(counter));
    }
    Thanks,
    Brandon K

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    Seems to be a mixture of Flash 4 and Flash 5 code.

    In Flash 5 and higher you dont use the & character to combine variables but the + character.

    setProperty("/menu"+counter)

    The slash syntax is not recommended anymore and may not be present in future players.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Junior Member
    Join Date
    May 2002
    Posts
    13
    figures...I guess thats what happens when you use an old tutorial.

    It still isn't working though:

    setProperty("menu"+(counter), _y, getProperty ( "menu"+(counter), _y )+"menuh"+(counter));

    Does it know that when I say "menuh"+(counter) I want it to determine which menuh variable it is...say menuh1 and use was it is defined as (in this case 14)... so it would be 14 in place of "menuh"+(counter)
    Thanks,
    Brandon K

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    If you want the value of menuh1 variable you have to use eval()

    +eval("menuh"+counter)

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Junior Member
    Join Date
    May 2002
    Posts
    13
    I don't think I can use eval because I am in MX...

    I attached my fla, maybe you can take a look?
    Attached Files
    Thanks,
    Brandon K

  6. #6
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    eval() is depreciated in MX and was replaced by the array element syntax, thus:
    Code:
    _root["menu"+counter]._y
    Will work for you (although eval() should still work)

  7. #7
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    In MX there is no indication of deprecation of eval().

    The array object does not evaluate.

    For instance, you may have a variable called whatever2.

    Then you can have
    a=eval("whatever"+i);

    to get a to display the value of whatever1.

    The array object can not do that to my knowledge.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  8. #8
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    For arguments sake, I take back the depreciation comment, maybe I was a bit hasty! But, the array object can indeed be used to evaluate:
    Code:
    this.createEmptyMovieClip("holder", 0);
    this.holder.lineStyle(1);
    this.holder.moveTo(-25, -25);
    this.holder.beginFill(0x000000);
    this.holder.lineTo(25, -25);
    this.holder.lineTo(25, 25);
    this.holder.lineTo(-25, 25);
    this.holder.lineTo(-25, -25);
    this.holder.endFill();
    for (i=1; i<=5; i++) {
        holder.duplicateMovieClip("holder"+i, i);
        _root["holder"+i]._y = i*55;
        _root["holder"+i]._alpha = i*20;
    }
    Try it out and observe the last 2 lines in the for loop affecting the alpha properties and the vertical position of the duped MCs. See?

    Cheers

  9. #9
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    But is that an evaluation. Isnt it just putting a string and a variable together to form the name of a movieclip.

    I mean.. If you have a variable var1=10;

    How would you combine "var"+1 to get the value, if not using eval()

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  10. #10
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    On some further reading it becomes apparant that in Flash 4 and 5, this is legal:
    Code:
    var count = 20;
    eval("identifier" + count) = "Dave";
    // sets identifier20 to "Dave"
    trace(identifier20);
    But due to the increase in keeping with ECMA-262 specificaction you can't use eval() on the left side of an operator, so in MX, you have to use
    Code:
    var count = 20;
    this["identifier" + count] = "Dave";
    trace(identifier20);
    If you try out the first code in MX you'll see that it fails.

  11. #11
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    Yes I know about leftside assignment and those things. Im curious if you could use my example with the array object.

    If I have...

    identifier1="dave";

    Can you then make "identifier"+count result in "dave" like

    // A will here get tha value DAVE
    a=eval("identifier"+count);

    How would you do it with the array thing?

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  12. #12
    Junior Member
    Join Date
    May 2002
    Posts
    13
    I have one more question for you experts.

    Using the code below, how can I get the links in a target frame (html code)?

    I swear this is in another language....

    traguardo = new Array(n.length);
    traguardof = new Array(fields.length);
    inizio = new Array(n.length);
    function traguardi() {
    cont = 0;
    for (i=0; i<n.length; i++) {
    nome = "oggetto"+i;
    if (i>tasto) {
    traguardo[i] = (i+n[tasto])*16+1;
    for (a=cont; a<cont+n[i]; a++) {
    traguardof[a] = traguardo[i];
    }
    cont = a;
    } else if (i<tasto) {
    traguardo[i] = inizio[i];
    for (a=cont; a<cont+n[i]; a++) {
    traguardof[a] = traguardo[i];
    }
    cont = a;
    } else if (i == tasto) {
    traguardo[i] = inizio[i];
    for (a=cont; a<cont+n[i]; a++) {
    if (a == cont) {
    prima = a-1;
    }
    traguardof[a] = 16*(a-prima)+traguardo[i];
    }
    cont = a;
    }
    }
    }
    clip._visible = 0;
    clip1._visible = 0;
    cont = 0;
    for (i=0; i<n.length; i++) {
    nome = "oggetto"+i;
    duplicateMovieClip(_root.clip, nome, i+100);
    traguardo[i] = i*16+1;
    inizio[i] = i*16+1;
    _root[nome].tasto = i;
    _root[nome]._y = i*16+1;
    _root[nome].title = titoli[i];
    for (a=cont; a<cont+n[i]; a++) {
    nome1 = "oggettonuovo"+a;
    duplicateMovieClip(_root.clip1, nome1, a);
    traguardof[a] = i*16+1;
    _root[nome1].field = a;
    _root[nome1].link = links[a];
    _root[nome1]._y = traguardo[i];
    _root[nome1].title = fields[a];
    }
    cont = a;
    }
    function spegni() {
    cont = 0;
    for (i=0; i<n.length; i++) {
    nome = "oggetto"+i;
    _root[nome].gotoAndStop(1);
    }
    spegni1();
    }
    function spegni1() {
    for (i=0; i<fields.length; i++) {
    nome = "oggettonuovo"+i;
    _root[nome].gotoAndStop(1);
    }
    }
    function chiudi() {
    cont = 0;
    for (i=0; i<n.length; i++) {
    nome = "oggetto"+i;
    _root[nome].gotoAndStop(1);
    traguardo[i] = inizio[i];
    for (a=cont; a<cont+n[i]; a++) {
    traguardof[a] = traguardo[i];
    nome1 = "oggettonuovo"+a;
    _root[nome1].gotoAndStop(1);
    }
    cont = a;
    }
    }
    Thanks,
    Brandon K

  13. #13
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    Originally posted by pellepiano
    How would you do it with the array thing?
    Yeah, I've just tried and it seems I can't without using our old friend eval() I was positively certain it could be done though, so I'm sorry for any confusion. I guess it's a lesson learned!

    Cheers

    (sorry for the thread hijack )

  14. #14
    Junior Member
    Join Date
    May 2002
    Posts
    13
    My idea was that you would add _root[nome1].targer = "mainFrame" here:

    duplicateMovieClip(_root.clip1, nome1, a);
    traguardof[a] = i*16+1;
    _root[nome1].field = a;
    _root[nome1].link = links[a];
    _root[nome1]._y = traguardo[i];
    _root[nome1].title = fields[a];
    Thanks,
    Brandon K

  15. #15
    Junior Member
    Join Date
    May 2002
    Posts
    13
    nevermind...I got it
    Thanks,
    Brandon K

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