Solved

help with script

Posted on 2004-10-31
172 Views
Last Modified: 2010-04-03
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
Question by:skylabel
    5 Comments
     
    LVL 16

    Expert Comment

    by:vickerleung
    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
     
    LVL 16

    Expert Comment

    by:vickerleung
    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
     
    LVL 16

    Accepted Solution

    by:
    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
     
    LVL 1

    Author Comment

    by:skylabel
    thank you sir!
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    You are welcome Skylabel ^^
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now