Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double-click to load new movie 1

Status
Not open for further replies.

eljacobs

Programmer
Oct 13, 2003
47
GB
I'm building an application where the user needs to double-click to load a new movie.

The code works for one button (buttonA) but i'm not sure how to loop it so that button B, button C, button D etc all do the same thing (but pass a different specified variable). I've tried repeating the code, but changing buttonA to button B but but i think there may be a clash of variables or something.

This is the code (it goes in frame 1 of the actions layer)

------------------------------

//set initial variables
click = false;
//function for the button press
buttonA.onPress = function() {
//if this is the first click
if (!click) {
timer = getTimer()/1000;
_root.click = true;
}
else {
timer2 = getTimer()/1000;
//if it is a double click
if ((timer2-timer)<.25) {
//load movie and pass variables
loadVariables("exemplar_variables.txt", "_root.target")
loadMovie("answers.swf",target);
_root.frame = 1;
} else {
timer = getTimer()/1000;
_root.click = true;
}
}
};

-----------------------------------------

Thanks

E
 
Hi E,

What you can do is create a single function using the code you have then for each button call that function on the onPress event. You can pass parameters to the function which reference the external movie and variable file to load.

So do something like:
//Create a function called doubleClick
//Variables = location of variables file
//Answer = location of swf file
function doubleClick(Variables,Answer) {
Your code here
}

Change the loadMovie and LoadVariable lines in your code to:
loadMovie(Answer,"target");
loadVariables(Variables, "target");

Then for each onPress event call the doubleClick function:
ButtonA.onPress = function() {
doubleClick ("exemplar_variables.txt","answer.swf");
};

ButtonB.onPress = function() {
doubleClick ("exemplar_variables2.txt","answer2.swf");
};

etc

Hope this helps. :)
Radiostar
 
I'm very sorry but i'm still confused by this. this is my first proper go at actionscripting and i'm learning as i go.

I understand the principle of what you have told me to do - create a single function then call that function later - but i'm unsure of how to structure the code.

I ended up with this which did not work. Can you see where i'm going wrong?

------------------------------------

stop();


function doubleClick(Variables,Answer) {

//set initial variables
click = false;
//if this is the first click
if (!click) {
timer = getTimer()/1000;
_root.click = true;
}
else {
timer2 = getTimer()/1000;
//if it is a double click
if ((timer2-timer)<.25) {
//load answer
loadMovie(Answer,"target");
loadVariables(Variables, "target");
_root.frame = 1;
} else {
timer = getTimer()/1000;
_root.click = true;
}
}
}

ButtonA.onPress = function() {
doubleClick ("exemplar_variables.txt","answer.swf");
}

--------------------------------------


Thanks for your help, much appreciated.

E
 
Hey E,

Sorry for the delayed response, didn't get a chance to check my mail on the weekend.

The code you have is almost correct, what's currently happening is that you're setting the variable "click" to false every time the function is called. So that means it's never going to perform the actions in the else statement. So what you need to do is move the statement click = false out of your doubleClick function statement.

So your code would look something like this in your first frame:

stop();

click = false;

function doubleClick(Variables,Answer) {
//Your code minus click=false;
}

ButtonA.onPress = function() {
doubleClick ("exemplar_variables.txt","answer.swf");
}

At the moment you're reseting the click variable back to false using _root.frame = 1. You can change this line of code to click = false and it will still work. That way you're reseting your variable within the function rather than having to move the playhead to reset the variable.

Cheers,
Radiostar

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top