[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

help with script

Posted on 2004-10-31
5
Medium Priority
?
183 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
Comment
Question by:skylabel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 16

Expert Comment

by:vickerleung
ID: 12460637
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
ID: 12460660
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:
vickerleung earned 2000 total points
ID: 12460696
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
ID: 12460723
thank you sir!
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12460748
You are welcome Skylabel ^^
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

650 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