[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

help with script

Hi,
I've got a movieclip with many graphic symbol instances, named tn1, tn2, tn3, tn4. When I click one of these, I want to open the appropriate links defined in the array called url. For some reason, whatever button I click on, I'm taken to url[3] (i.e. four.swf). Here's my code. Any ideas?


function loadPage(target){
     geturl(target);
}
onclipEvent (load) {

  url= new Array();
   url[0]="one.swf";
   url[1]="two.swf";
   url[2]="three.swf";
   url[3]="four.swf";
   
   for (x=1; x<=url.length; x++){
      target=url[x-1];
      ("tn" + x).onRelease=function() {
              loadPage(target);
              }
     } //end for
}
0
skylabel
Asked:
skylabel
  • 4
1 Solution
 
vickerleungCommented:
Skylabel,

Actually I don't think that this line of code will work
("tn" + x).onRelease=function() {

You can't specify an instance like that
(If I am wrong, someone please let me know)

What I suggest here is the following


function loadPage(target){
     geturl(target);
}

onclipEvent (load) {

  url= new Array();
   url[1]="one.swf";
   url[2]="two.swf";
   url[3]="three.swf";
   url[4]="four.swf";
   
   for (x=1; x<=url.length; x++){
      target=url[x];
      temp_instance_name = "tn" add x;
      _root [temp_instance_name].onRelease=function() {
              loadPage(target);
              }
     } //end for
}

Hope it works~!! :)
Vicker
0
 
vickerleungCommented:
Skylabel,

I am sorry that mislook the scripts

Actually the line of error is this line

loadPage(target);

Because this line is inside your clip event section
So actually when you click the button,
It will use the latest value of target
in this case url [3];

So in order to do what you wanna do,
You have to rewrite that part
Give me some time and I will give you a sample file

Vicker
0
 
vickerleungCommented:
Skylabel,

The modified script is like this

onClipEvent (load) {
      url = new Array();
      url[1] = "one.swf";
      url[2] = "two.swf";
      url[3] = "three.swf";
      url[4] = "four.swf";
      for (x=1; x<=url.length-1; x++) {
            target = url[x];
            temp_instance_name = "tn" add x;
            this[temp_instance_name].url_target = target;
            this[temp_instance_name].onRelease = function() {
                  loadPage(this.url_target);
            };
      }
      // end for
}


Actually the idea is that storing the url inside the button itself
(i.e. this[temp_instance_name].url_target = target;)

And then when you call the function, it will use the url stored
(i.e. loadPage(this.url_target);)

Sample file in here
http://www.geocities.com/vickerleung/button_url.zip

Vicker :)
0
 
skylabelAuthor Commented:
thank you sir!
0
 
vickerleungCommented:
You are welcome Skylabel ^^
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now