How do I get my Flash CS4 buttons to direct the user to another URL?
My apologies if this has been fully addressed before, but I've read through several other threads and still can't seem to get my file to work.
My actionscript code is at the bottom of this message. I created it using instructions from the Adobe website: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7fd7.html
I believe I've all of my objects set to the correct type of symbol (button) and all of my instances are named appropriately (see screenshot here: www.footprintsfamilyphoto.com/wp-content/themes/Footprints/images/flash_buttonissue.jpg)
Action Script here. Let me know if you have suggestions! (Note: I am very new to Flash):
stop ();
function babieschildren(event:MouseEvent):void
{
trace("babies children method was called!!!");
var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/babies-children");
navigateToURL(targetURL, "_self");
}
bc_btn1.addEventListener(MouseEvent.CLICK, babieschildren);
bc_btn2.addEventListener(MouseEvent.CLICK, babieschildren);
function families(event:MouseEvent):void
{
trace("families method was called!!!");
var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/families");
navigateToURL(targetURL, "_self");
}
f_btn1.addEventListener(MouseEvent.CLICK, families);
f_btn2.addEventListener(MouseEvent.CLICK, families);
function couplesweddings(event:MouseEvent):void
{
trace("couples weddings method was called!!!");
var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/couples-weddings");
navigateToURL(targetU开发者_StackOverflow社区RL, "_self");
}
cw_btn1.addEventListener(MouseEvent.CLICK, couplesweddings);
cw_btn2.addEventListener(MouseEvent.CLICK, couplesweddings);
Additional description of Flash file - file is an approx 5 second animation that should stop on the last frame. The last frame contains 6 buttons which should route the user to 3 different pages of the website. Refer to screenshot image link above.
Alright, I tried a couple more things, I changed the "families" function to "fams" since for some reason it was telling me that it was a duplicate function. That resolved the looping issue (the file was looping instead of stopping on the frame where these buttons are located, and I was receiving compilation errors about the families function - "duplicate function definition" and "incompatible override" - I'm fairly confident it's not a duplicate function, as this is the only action script that I have in this entire file...).
Now it stops on the right frame, the compilation errors appear to be resolved, but I don't see the trace statements in the output box when I click on the buttons. I do get an initial error in the output box when I test the movie, it reads:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Portfolio_fla::MainTimeline/frame133()
Can anyone let me know what that means?
i've checked and rechecked all the button names (and instance names), they're all there, right in the same frame as the action script (frame 133), so that shouldn't be causing the 1009.
Also just removed each function and addEventListener set one by one and tested the movie, but the 1009 error persisted in all 3 cases. I do not get the 1009 error if I delete all of the code other than "stop ();" and test the movie.
Note: I've opened a new, more specific question regarding the 1009 error here: stackoverflow.com/questions/2948119/flash-buttons-dont-work-typeerror-error-1009-cannot-access-a-property-or-met
You code looks fine. Add trace statements in the methods to make sure they're indeed called. Also check for any pop-up blockers; when you call navigateToURL without the second parameter, Flash will try to create a new window to open the URL in. Unfortunately for us developers, (and fortunately for users), most of the pop-up blockers will prevent this from happening. Add the second parameter to your calls and see if it works.
navigateToURL(targetURL, "_self");
Note that this will cause the new URL to be loaded in the current window/tab, effectively replacing the page that has your SWF
精彩评论