PDA

View Full Version : Action Script Question...


The Repro Kid
03-30-2008, 04:14 PM
I have a question for an Action Script Whiz.

I'm adding a bit of flash elements to my web page. On Lynda.com there is a pretty nice example of adding an Invisible Button to a banner, so that when the button is clicked on it opens up a URL in a new window. Simple enough.

My situation is I want to adapt this action to an intro page for my web site. So, the index file of my web site is just a page with one animated banner which has the invisible button, and when the user clicks on the animation, it then brings the user to the true intro page of my web site.

But here's the deal, I don't want it to open in a new window. I want it to open in the same window. In Dreamweaver I believe this is referred to as the Hyperlink target being "Self" not "New." But I can't figure out how to modify the script to not open in a new window.

I've tried some obvious things like changing the word New to Self, or just removing the word new, but neither of these things work. I looked through the scripting assistant, which hasn't clued me in, and I've waded through the documentation, which has not helped either. I feel as though unless I actually knew what to do, then I would not be able to find the answer in the reference material :confused:

Here is the code, it is Action Script 3:

1. bttnHope.addEventListener(MouseEvent.CLICK, buttonClickHandler);
2. function buttonClickHandler(event:MouseEvent):void {
3. navigateToURL(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm"));
4. trace("I'm clicked");
5. }

This script works just fine, but it opens a new window, I'd like it to open in the same window.

Here is a link to the whole site so you can see the button open the URL in the new window:

www.mendozaproductions.com


Thanks for any help out there.

The Repro Kid
03-31-2008, 02:25 AM
Hmm... seems like such a simple question...

...no scripting experts out there?

ldrain
03-31-2008, 04:57 PM
did a quick google search:


navigateToURL(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm"), "_self");

the difference is: , "_self"

you were on the right track at least! there's lots of case-sensitivity involved with scripting, it will get you over and over again for a very long time. hope it works out.

The Repro Kid
03-31-2008, 05:06 PM
Yes! thanks! I'll give it a try!

You mean self is preceded by an underscore??? How Rude! :rolleyes:

If you don't mind, how on earth were you able to look it up? I'd really like to learn how to fish in this case, not just eat one.

[edit] Wow I just read the code more carefully, that's weird how it's written.

Should it look like this:
(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm"), "_self")

or this:
(_self URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm")

ldrain
03-31-2008, 05:11 PM
i figured that the "navigateToURL" method(?) was where the problem may lie.

so i started google on that, got a lot of "Flex" results. added in "actionscript" which got me closer, then i added in "no pop-up" which gave me a few up top. there was another forum where someone had answered a similar question. so i ended up with "navigateToURL, actionscript no pop-up" in the google search bar. i have some scripting background(javascript, actionscript before it changed) so i have an idea of what to look for, which helps :D

ldrain
03-31-2008, 05:12 PM
this one:

(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm"), "_self")

The Repro Kid
03-31-2008, 05:30 PM
Okay, got it, and thanks on the search tips.

The Repro Kid
04-01-2008, 05:21 PM
Well it sounded good on paper idrain, but I can't get it to work. Everything looks right, I get all the correct colored text and don't get any compile errors when publishing, but I can't get a response after clicking on the button. The animation still works, which often doesn't if get a compile or syntax error, but nothing happens after clicking. It just continues to loop and doesn't open any URL.

I don't suppose you have any ideas. I haven't tried uploading it to my FTP as I don't know why that would make a difference, but maybe I'll try it.

ldrain
04-01-2008, 09:02 PM
try getting rid of that ':void ' after (event:MouseEvent).

i think that is telling it to void the click (which you would use to open the new window, kind of a long explanation), so nothing will happen when you click it. :rolleyes:

also, are you checking it in a browser or just the flash player? try it in a browser if you haven't, but i still think the void is getting in the way.

forgot to check here today, on my way out the door. i'll be able to put some more head time into it tomorrow

The Repro Kid
04-01-2008, 10:24 PM
Don't sweat it. I can always take it down for the time being if it bugs me enough. When previewing, my flash is set up to temporally publish and then open in Safari. I don't use flash player to preview. And then further, when the swf file gets into my quark web layout, again quark will temporarily export the html to Safari. If it doesn't preview through safari in Flash, then I don't bother bringing it over to quark to further test.

I tried zapping the void command but nothing changed. But again, I didn't a get compile or syntax error, which always pleases me because I seem to get those a lot :o

ldrain
04-02-2008, 02:34 PM
i think i got it now.

first thing, i screwed up with my last advice, i think you need the ':void' in there, sorry :o

second, it has to do with the ()!!!
should look like so:

navigateToURL(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm", "_self"))


here's the link (http://board.flashkit.com/board/archive/index.php/t-748348.html) to where i got the info. it seems as though you are using the same tutorial.

third, i was looking at the html for the flash page and noticed the .swf was called "New Logo xxxx". with just about anything that has to do with the web and servers, using spaces in file names are a very, very bad habit. i don't know the exact specifics, but i have had strange problems before. the alternative would be to use underscores or just get rid of the spaces and use the uppercase/lowercase scheme that you already have.

anyway, hope that ACTUALLY helps this time. :rolleyes:

The Repro Kid
04-02-2008, 03:34 PM
Yes, I have a bad habit of leaving spaces in my web file names. I've been trying to correct that everywhere I can. I build my pages with Quark and when quark exports it corrects those for me by adding % signs or whatever, but I wish it wouldn't, it just reinforces a bad habit. I wish it would give me a warning instead, so I could go back and fix it. From what I remember of Dreamweaver, you had to correct it or it wouldn't work.

Thanks for the link. It makes more sense, because that's how the previous script ended.

I thought the tutorial was Lynda but come to think of it, it was from the Adobe Workshop.

Here is the tutorial if you are interested. I'd post a link but you can't access the link directly.

ldrain
04-02-2008, 04:10 PM
so does it work? im dying here...

The Repro Kid
04-03-2008, 06:44 AM
even the puny little repro kid has his moments.

The Repro Kid
04-03-2008, 10:17 AM
Yeah no just tried it. maybe I'm just not cut out for scripting? It seems a bit complicated.

ldrain
04-03-2008, 02:48 PM
fooey, can you post a pic of what the code looks like now?

The Repro Kid
04-04-2008, 05:08 PM
Here's a shot of how it looks now.

If it was working, then temporarily publishing to safari from flash should work and open the URL. Instead, everything plays, the button shows up as clickable, but nothing happens when clicked.

So when it fails in the Flash Publish Preview, I don't go any further with it. But this time I went ahead and brought it into quark and exported the HTML and still it won't work from there either.

I'll study the code from the link you provided and see it there is something I am missing.

ldrain
04-04-2008, 07:38 PM
only thing i noticed on this one which might cause a problem, is that you left out the ';' after the whole _self line. don't know, could fix it.

everything else seems to be the way it should be. sorry i couldn't be more help. surprised no one else chimed in. :(

The Repro Kid
04-05-2008, 01:20 AM
are you saying that the last comma should be a semi and not a comma?

that's the problem with progammers, they are lazy!!! a comma is not a semi!!! sorryif I dont speak your langauage!!!! get accurate and specify!!!!!!

Okay I'm done:p

not you idrain, the authors of the stinking tut!

ldrain
04-07-2008, 02:55 PM
oy, sorry about that. i'll try to explain better.

the line (which i realize i probably screwed you up in a previous post by not including the semicolon) should look like this:

navigateToURL(new URLRequest("http://www.mendozaproductions.com/production/IntroPage/IntroWeb.htm", "_self"));

the change being the semicolon at the end.

a semicolon is generally the end of a statement, like a period in a sentence. without the semicolon, the script keeps looking for more directions in that line of code. so without the semicolon in that statement, the function doesn't even reach the trace() or the end of the function, which is probably why nothing is happening. well i hope so anyway. :D

hope that makes more sense!

The Repro Kid
04-08-2008, 03:45 AM
it makes sense, especially when you 'spained it. Am I blind? Did the original post (not yours, the one from the forum) include the semi? I am getting old and tired you know ;) Trying to learn someting new at my advanced is a bit of a challenge. :o

ldrain
04-08-2008, 02:37 PM
it makes sense, especially when you 'spained it. Am I blind? Did the original post (not yours, the one from the forum) include the semi? I am getting old and tired you know ;) Trying to learn someting new at my advanced is a bit of a challenge. :o

trying to learn anything at 11:45 at night could prove to be quite a challenge for anyone. but it did look like the semi was in the other post, it happens :p

The Repro Kid
04-09-2008, 11:09 AM
¡mi mente!