A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Can this be done in an array???

  1. #1
    Abandon all Hope Inflicted's Avatar
    Join Date
    Aug 2003
    Location
    Harlem A+, Netherlands
    Posts
    296

    Can this be done in an array???

    I have a movie with 6 containers that load jpg's: container_1, container_2 etc.
    They all have the same action. Instead of copying the code for every instance, can I put this in an array?

    How would I do that? Couldn't find the appropriate tut or thread.

    code:
    container_1._alpha = 0;
    this.onEnterFrame = function() {
    loadMovie("image1.jpg", "container_1");



    Any help's appreciated!

    regards
    regards

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Posts
    135
    something like

    for(var cnt=0; cnt<6; cnt++){
    var mc = eval("container_"+cnt);
    mc._alpha = 0;
    mc.onEnterFrame = function() {
    loadMovie("image1.jpg","container_"+cnt);
    }
    }

    -Mav

  3. #3
    Abandon all Hope Inflicted's Avatar
    Join Date
    Aug 2003
    Location
    Harlem A+, Netherlands
    Posts
    296
    Thanks for your reply!

    I got it to work, now have a follow up question:

    I want the containers to load the jpg's with some delay between loading container_1, container_2 etc.

    I tried putting the containers on a seperate frame, container_1 on frame 1, container_2 on frame 2 etc...Doesn't work.

    Do you know of a way to do this?

    Thanks again,

    regards
    regards

  4. #4
    Senior Member
    Join Date
    Oct 2001
    Posts
    135
    instead of a for statement, put the code inside a function and use setInterval to call the function. You can control the timing thus.

    ofcourse you need maintain 'cnt' at each function call.

    -Mav

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