PDA

Click to See Complete Forum and Search --> : 2 getURLs on 1 button...



Pants234
02-15-2007, 10:31 PM
I have some buttons and each one needs to go to a URL and call a javascript function. This is the code that I have on the buttons now.

on (release) {
getURL("javascript:OnLookup('3')");
getURL("Travel/TripTik/Index.aspx", "");
}

It seems to me like this should work, but it isn't. Am I not allowed to have 2 getURLs in the same action? Or is there something that I am missing here. Any insight would be great!! Thanks!

Chris_Seahorn
02-15-2007, 11:41 PM
Whole bunch of options here....don't forget you have two edges to the button sword

on(press)

and

on(release)


even that aside you can always wrap each getURL in tiny functions that call each other sequentially :)

Button fires first function (which is basically a getURL) on press and fires a second function (which is another getURL) on release...etc etc

Genesis F5
02-16-2007, 10:38 AM
You're allowed two getURLs. Heck, you can have a hundred if you want, but look at where you're targetting. By leaving the target area blank ("") you're telling Flash to open the link internally. Is that what you want? If you want separate pages, you need to get a blank page: getURL("www.somewhere.com","_blank").

I'd suggest using a timed delay, but that's messy since browers take different amounts of time to load pages / parse information.

Pants234
02-16-2007, 11:42 AM
The script that I am using to redirect the page is working fine...it is the javascript call that isn't working correctly.

I changed it so the js calls on(press) and the redirect calls on(release). It seems like the js doesn't finish running before the page redirects, thus the js is not working correctly.

I a not a great Action scripting and I think that i may need to use some functions here. Any help with this would be greatly appreciated.

Thanks!

Genesis F5
02-16-2007, 11:58 AM
Well, like I said, to use functions, you have to rely on a timer. The problem with that is how do you know when to submit the second request? I guess you could have the first function return something to flash to signal an acknowledge / request type handshake, but I think you might be better off handling the redirect from the first javascript function.

So, Flash calls the Javascript function and then the function does the redirect.

Pants234
02-16-2007, 12:22 PM
I think you may be right here. We'll try this and see....thanks!

Pants234
02-16-2007, 04:02 PM
ok, so now this has become a lesson in ExternalInterface.

For learning purposes, can anyone tell me how they would call this javascript using ExternalInterface:

on (release) {
getURL("javascript:OnLookup('3')");
}

Pants234
02-16-2007, 05:20 PM
Don't everyone reply at once :)

Now I have this code:

on (release) {
import flash.external.ExternalInterface;
ExternalInterface.call("OnLookup", "3");
}

but it doesn't work. Anyone know why?

jasonsplace
02-16-2007, 07:25 PM
You could always just call the JavaScript from flash and then have it redirect you when it's done.

Genesis F5
02-16-2007, 08:16 PM
Do this:

HTML

<html>
<body>

<script script="javascript">
function testfun(test)
{
alert(test);
}

</script>


<embed src="externalinterface.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="external interface"

align="middle" allowScriptAccess="always" swLiveConnect="true" type="application/x-shockwave-flash"/>

</body>
</html>

ACTIONSCRIPT (FIRST FRAME)

import flash.external.*;

var test:Number;
test = 10;

onMouseDown = function()
{ ExternalInterface.call("testfun", test);
}

Does that work for you? Don't export a Flash HTML page to test. I kept getting some semicolon error. Stripping the object tag and parameters seemed to fix it.

Pazil
02-17-2007, 10:17 PM
You people seem like really good javascripters, and...I really want to take javascript off my "to-learn" list (not that I seriously have one), since I heard that java is a pretty hard language to learn...Give me a link atleast, since I'm learning PHP which is kinda hard to take in, even though it is similiar to actionscript as well...anyways, any help is awsome!

Genesis F5
02-17-2007, 10:53 PM
I found Javascript to be an incredibly easy language to learn. It's syntax is akin to that of Actionscript and C. Same format structure as far as functions go and it uses all of the standard stuff you'd find in both of the languages.

Straight Java is quite a bit different from its embedded script counterpart. It's based more on C with a hint of Perl. Look at some example source here (http://www.java2s.com/) to see what it's like.

For Javascript, I recommend w3schools (http://www.w3schools.com/js/default.asp) for all the basics. Everything else will come with practice. :)

Pazil
02-18-2007, 11:13 AM
Thanks! I heard it was similiar to actionscript, though at the same time I heard it was hard, but I'll try w3schools (they taught me html), since I like how they teach. Anyways, thanks a million!