A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: array help! almost done with site

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1

    array help! almost done with site

    Hi everyone.

    So I have been working on my site for a week or so now, just teaching myself flash and I am running into one last hiccup. My site is for my photography, and at the bottom of the picture, I have a rollover button that displays the caption that goes with the photo. The rollover works fine, but the problem is that when I click the next symbol to advance to the next caption, it skips to the last caption in the sequence and only displays that one, until I go all the way to the end of the 19 images, and on the way back, it starts displaying the captions correctly. Also, the first caption is displayed as "undefined."

    I think the problem lies somewhere in this code:

    info.onRollOver=function() {
    dt.text = capArray[i];
    }
    info.onRollOut=function() {
    dt.text = "";
    }
    forward.onRelease = function() {
    i<18?i++:i=18;
    }
    back.onRelease = function() {
    i>0?i--:i=0;
    }


    but I am not exactly sure. I've attached the files, someone could check it out and let me know whats going on, that would be amazing!

    thanks.
    Attached Files Attached Files

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    the source files give me "Unexpected file format" i'm using CS3, probably CS4 file, if you could save as CS3 or earlier, i can check it out for ya.

    if the first caption is "undefined" it's usually because all Arrays start from 0.

    var myArray:Array = new Array("one","two","three");
    //myArray[0] = one
    //myArray[1] = two
    //myArray[2] = three

    when calling array values, use myArray[i-1] and that should work.

  3. #3
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    ok, looked it over, had to install CS4

    It seems if you trace(i) at the bottom of the code of frame 3, it traces: 20, so "i" is set to 20 somehow. I also noticed that you use the variable "i" alot in the same frame.
    "i" is a local variable, so it shouldn't be used more than once outside of any functions or statements.

    just change your variable "i" to "a" like so, so that other statements won't affect it.

    Actionscript Code:
    var a:Number = 0;

    info.onRollOver=function() {
        dt.text = _root.capArray[a];
    }
    info.onRollOut=function() {
        dt.text = "";
    }
    forward.onRelease = function() {
        a<18?a++:a=18;
    }
    back.onRelease = function() {
        a>0?a--:a=0;
    }
    Good luck

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