SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2002
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    random image/link runs twice then breaks?

    I'm trying to get a simple script to run where it cycles thru a few images with corresponding links and displays them on a page.

    I get the script to run 2 times then it breaks on the third with a runtime error saying "object expected Line 0".

    Here's the code, it's totally "body" code.

    <script language="Javascript">
    <!--

    function rotator() {
    var currentdate = 0;
    var core = 0;
    var Rtime = 2000

    function initArray() {

    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
    this[i] = initArray.arguments[i];
    }
    }

    link = new initArray(
    "http://www.yahoo.com",
    "http://www.nike.com",
    "http://www.sitepoint.com/"
    );

    image = new initArray(
    "pic1.gif",
    "pic2.gif",
    "pic3.gif"
    );

    text = new initArray(
    "Picture 1",
    "Picture 2",
    "Picture 3"
    );

    var currentdate = new Date();
    var core = currentdate.getSeconds() % image.length;
    var ranlink = link[core];
    var ranimage = image[core];
    var rantext = text[core];


    document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"><br>'+rantext+'</a>');
    setTimeout("rotator()", Rtime)
    }
    rotator();

    //-->
    </SCRIPT>

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I see something wrong, but I might be wrong.

    You're creating new objects by calling your own constructor function (not sure why - but hey thats your call).

    Anyway I don't think objects are automatically arrays.

    So for example you have a line:
    Code:
    this[i]="blah"
    However I think you have to do:
    Code:
    this.array = new Array();
    this.array[i] = "blah"
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel


Bookmarks

Posting Permissions

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