View Full Version : call javascript
akschinas
06-30-2003, 03:11 PM
Hello. I'm looking for a way to call javascript when you hit a button. I need to send variables to an HTML frame, but I'm not sure how to script it. Thanks!
jaybee
07-01-2003, 09:16 AM
hello akschinas, have you searched the forum? this gets covered a lot, eg here (http://www.actionscript.org/forums/showthread.php3?s=&threadid=30288)
akschinas
07-06-2003, 03:04 PM
I have searched but not found exactly what I'm looking for, or maybe I missed it. I don't want to open a new window, so therefore would I use getURL? I just need to pass a variable to a frame, so would I use fscommand or getURL? I'm just not sure how to simply call a javascript. THanks
jaybee
07-06-2003, 03:18 PM
whether or not you're opening a new window/pop up you can use getURL to call a javascript method in the html page:
//in your movie
my_button.onRelease = function() {
getURL("javascript:myFunction(1);void(0);");
}
//in a script block in your html page
function myFunction(arg) {
//set a variable in a frame
window.parent.namedFrame.document.myVar = arg;
}
akschinas
07-08-2003, 12:40 AM
O.k. I kind of got it. However, I'm not really sure what this means:
getURL("java script:myFunction(1);void(0);");
I have to score a quiz and pass that score to an HTML page called "frameset.htm". Where do I call that page in the actionscript? Would "myFunction" be replaced with "myScore" since I am trying to pass a score to the frameset.htm? What does the "1" mean in parentheses? What does void mean? Sorry about the questions, I just want to fully understand. Thanks!
jaybee
07-08-2003, 09:29 AM
send the score to the other frame with a getURL action either on a frame or on a button / whatever - do it when they finish the quiz and you've calculated the score.
myFunction() is an arbitrary name - call it whatever you like, as long as it has the same name in the html page and in the getURL call in flash.
The *1* in brackets is the argument passed to the function - you coulod pass the score in there, but if you want to pass the value of a variable instead of something hardcoded, you'd do it like this:
my_button.onRelease = function() {
var theScore = answer1+answer2+answer3;
getURL("javascript:myFunction("+theScore+");void(0);");
}
void is a javascript keyword - it tells the browser not to do whatever it would normally do next - which in this case is to open a new window - so this getURL just executes the javascript the stops.
Sorry about the questions
don't be daft:)
akschinas
07-08-2003, 03:23 PM
You're the best. You helped me greatly on another project. Thanks again!
akschinas
07-09-2003, 01:32 AM
Now I have found out that it gets more complicated! I have to talk to a frame within an HTML page. The page is named frameset.htm and the name of the frame within frameset.htm is called navbar. Navbar is where I need to pass the score. So how would I direct the score variable to the navbar? Here's the code you gave me. Where would I put navbar in the script?
my_button.onRelease = function() {
var theScore = answer1+answer2+answer3;
getURL("javascript:myFunction("+theScore+");void(0);");
Thanks alot!
jaybee
07-09-2003, 11:23 AM
put it in the javascript :
function myFunction(score) {
window.parent.navFrame.document.theScore = score;
}
This javascript should be in the page containing the movie which is in a frameset that also contains another frame called navFrame.
I dunno if the document part of that path is right offhand.....try it with and then without if it doesn't work.
akschinas
07-14-2003, 04:50 PM
HI Jaybee,
I'm so close I can feel it! The forum won't allow me to attach the movie becuase it's saying that it's too big. Anyway, here is javascript in my htm page:
//The following code returns the score
function myFunction(score){
window.parent.navFrame.document.lesson_score=score ;
}
//The following code returns the grade
function myFunction(grade){
window.parent.navFrame.document.lesson_grade=grade ;
}
//The following code returns the attempts
function myFunction(attempts){
window.parent.navFrame.document.lesson_attempts=at tempts;
}
Here is the actionscript which is on the first frame of my movie:
onEnterFrame();
var lesson_attempts=+1
getURL("javascript:myFunction("+lesson_attempts+");void(0);");
Here is the actionscript which is on the last frame of my movie:
onEnterFrame();
var lesson_score=QuizTrack.lesson_score
getURL("javascript:myFunction("+lesson_score+");void(0);");
var lesson_grade=QuizTrack.lesson_grade
getURL("javascript:myFunction("+lesson_grade+");void(0);");
It just doesn't work! When I play the swf file outside of the HTM file attached to it, it opens up new windows and gives me the info I asked it to track. But when I view it within the HTM file with the javascript in it, there's nothing. Thanks again!
jaybee
07-15-2003, 09:59 AM
your functions in javascript should have unique names - I'd suggest one function to send any variable, so like this:
//The following code returns the score, grade or attempts
function myFunction(name,value){
window.parent.navFrame.document[name]=value;
}
then call it from flash like this:
var lesson_attempts=+1
getURL("javascript:myFunction('lesson_attempts',"+lesson_attempts+");void(0);");
no need for the onEnterframe there - if this code is on the frame then its executed - enterFrame is used to execute code repeatedly from within the timeline of a movieclip....
var lesson_score=QuizTrack.lesson_score
getURL("javascript:myFunction('lesson_score',"+lesson_score+");void(0);");
var lesson_grade=QuizTrack.lesson_grade
getURL("javascript:myFunction('lesson_grade',"+lesson_grade+");void(0);");
akschinas
07-16-2003, 02:18 PM
Genius! It works! Thanks so much!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.