View Full Version : Button and navigation problems :(
studio01
May 9th, 2009, 07:15 PM
Hi there fello action scripters i am having a serious problem with my navigation my file just doesnt seem to work heres the code:
stop();
function navigation(event:MouseEvent):void{
gotoAndStop(event.target.name);
trace("button was clicked");
}
home_btn.addEventListener(MouseEvent.CLICK,navigat ion);
news_btn.addEventListener(MouseEvent.CLICK,navigat ion);
about_btn.addEventListener(MouseEvent.CLICK,naviga tion);
portfolio_btn.addEventListener(MouseEvent.CLICK,na vigation);
contact_btn.addEventListener(MouseEvent.CLICK,navi gation);
I have labels home, news, about, portfolio, contact.
i keep getting this error ArgumentError: Error #2109: Frame label instance6 not found in scene Scene 1.
at flash.display::MovieClip/gotoAndStop()
at whywontyouworkdamyou_fla::MainTimeline/navigation()
and my buttons dont work iver lol how hard is AS3 what have they done to it :(
Please help :(
ill upload the FLA in a sec if anyone could please take a peek this is for a project at uni i need to have it handed in by monday and ive been stuck with this problem since 15:00 in the afternoon uk time and its now 22:15 :(
heads fried now...
Edit im seeing spaces in the word navigation why rofl its ok in edit mode?!?!
Edit:the Fla http://www.d1gitalanarchy.com/whywontyouworkdamyou.fla
snickelfritz
May 9th, 2009, 08:43 PM
This will be looking for "home_btn", "news_btn" etc..., since those are the instance names of your buttons, and the buttons are the "event.targets".
Even if you fix the current error, you will still receive an error that cannot find frame label "home_btn".
gotoAndStop(event.target.name)
You probably have an unnamed mouseEnabled object within your buttons, which is why you are getting "instance6" in your error message.
By default, mouse events propagate to nested objects in AS3 when using "event.target".
Using "event.currentTarget" will instruct Flash Player to use the parent object as the target, rather than mouseEnabled objects nested within it.
gotoAndStop(event.currentTarget.name);
Another valid approach is to set mouseChildren to false for the buttons.
In simple terms, this stops events from propagating to nested objects, even when using event.target.
home_btn.mouseChildren = false;
studio01
May 9th, 2009, 08:57 PM
Hey snickelfritz (http://www.kirupa.com/forum/member.php?u=102867) thanks for replying i have tryed to fix the problem by adding what you suggested and im still getting the error :S also the stop(); action just isnt work lol ?!?!
this is just lame...
heres the code!
stop();
function navigation(event:MouseEvent):void{
gotoAndStop(event.currentTarget.name);
trace("button was clicked");
}
home_btn.mouseChildren = false;
home_btn.addEventListener(MouseEvent.CLICK,navigat ion);
news_btn.addEventListener(MouseEvent.CLICK,navigat ion);
about_btn.addEventListener(MouseEvent.CLICK,naviga tion);
portfolio_btn.addEventListener(MouseEvent.CLICK,na vigation);
contact_btn.addEventListener(MouseEvent.CLICK,navi gation);
home_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.google.com/"));
}
//////////////// Loading CSS HTML //////////////////////////
var cssUrl:URLRequest = new URLRequest("default.css");
var cssLoader:URLLoader = new URLLoader();
cssLoader.load(cssUrl);
cssLoader.addEventListener(Event.COMPLETE,cssLoade d);
function cssLoaded(event:Event):void {
var css:StyleSheet = new StyleSheet();
css.parseCSS(URLLoader(event.target).data);
tField.styleSheet = css;
}
var textUrl:URLRequest = new URLRequest("homepage.txt");
var textLoader:URLLoader = new URLLoader();
textLoader.load(textUrl);
textLoader.addEventListener(Event.COMPLETE,fileLoa ded);
function fileLoaded(event:Event):void {
tField.htmlText= event.target.data;
tField.background = true;
tField.backgroundColor=0x000000;
}
//////////////// Loading XML Players //////////////////////////
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("playlist.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_songs = myXML.SONG;
my_total = my_songs.length();
//playSong(0);
myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader = null;
}
function playSong(mySong:Number):void {
var myTitle = my_songs[mySong].@TITLE;
var myArtist = my_songs[mySong].@ARTIST;
var myURL = my_songs[mySong].@URL;
title_txt.text = myTitle;
artist_txt.text = myArtist;
if (my_channel) {
my_channel.stop();
my_channel.removeEventListener(Event.SOUND_COMPLET E, onNext);
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
}
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void {
current_song++;
if (current_song>=my_total) {
current_song=0;
}
playSong(current_song);
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void {
current_song--;
if (current_song<0) {
current_song = my_total-1;
}
playSong(current_song);
}
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {
if (my_channel) {
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
}
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {
if (song_paused) {
my_channel = my_sound.play(song_position);
song_paused=false;
} else if (!my_channel) {
playSong(current_song);
}
}
///////////////images//////////////////////
var pHeight:Number = 307;
var pWidth:Number = 384;
var listLoader:URLLoader = new URLLoader( new URLRequest("filelist.xml") );
var picLoader:Loader = new Loader();
listLoader.addEventListener(Event.COMPLETE, gotList);
function gotList(evt:Event):void {
var xmlData:XML = XML(listLoader.data);
var numImages:Number = xmlData.pix.length();
var stImage:String = xmlData.pix[Math.floor(numImages*Math.random())].toString();
picLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, gotPic);
picLoader.load( new URLRequest(stImage) );
listLoader.removeEventListener(Event.COMPLETE, gotList);
}
function gotPic(evt:Event):void {
var thisBmp:Bitmap = Bitmap(evt.target.content);
thisBmp.x = 318;
thisBmp.y = 220;
var thisWidth:Number = thisBmp.width;
var thisHeight:Number = thisBmp.height;
thisBmp.scaleX = pWidth/thisWidth;
thisBmp.scaleY = pHeight/thisHeight;
addChild(thisBmp);
picLoader.contentLoaderInfo.removeEventListener(Ev ent.COMPLETE, gotPic);
}
studio01
May 9th, 2009, 09:26 PM
Ok i managed to fix the probelm thanks allot for the help :)
PS: can anyone explain why my standard "button" doesnt show its roll over state i have set it to tint but yeah it doesnt do anything i think its a movieclip inside the button... ohh dear just realised rofl...
var nextSection:String = "";
//add button event listeners
home_btn.addEventListener(MouseEvent.CLICK, navigate, false, 0, true);
news_btn.addEventListener(MouseEvent.CLICK, navigate, false, 0, true);
about_btn.addEventListener(MouseEvent.CLICK, navigate, false, 0, true);
portfolio_btn.addEventListener(MouseEvent.CLICK, navigate, false, 0, true);
contact_btn.addEventListener(MouseEvent.CLICK, navigate, false, 0, true);
//define the function each button will call
function navigate(evt:MouseEvent):void {
trace("the button was clicked yes it was");
//the destination frame label is derived from the name of the button clicked
nextSection = evt.target.name;
play();
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.