Jump to content


Application keeps opening the same URL, have no idea why


  • You cannot reply to this topic
12 replies to this topic

#1 Nicodemus36Q

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 12 March 2007 - 12:28 PM

Hi I'm developing my convergence project and it's a sort of game for PSP that accesses the internet. Everything about it works pretty much okay except there comes a point when the user goes onto a menu screen and accesses scrolls that open web pages. For the first frame they press X and the page opens then they progress to the next frame and even though the keylistener has been removed and replaced by one where x opens a different URL the same webpage opens up. I can't see anything wrong with the actionscript and the same method works earlier in the program. Anywhere here's the code I have if you have time maybe you could look at it and see what you can do.

On a layer above frame 14 is Key.removeListener(keyListener);

keyListener = new Object();
keyListener.onKeyDown = function() {
x = Key.getAscii();
if(x == 88) {
getURL("http://www.youkaimura.org/ashima.htm":angrylooking:;

} else if(x == 62) {
nextFrame();
}else if(x==76){
frame=9;
gotoAndPlay(frame);
}
}
Key.addListener(keyListener);

On the next frame is:
Key.removeListener(keyListener);

keyListener = new Object();
keyListener.onKeyDown = function() {
x = Key.getAscii();
if(x == 88) {
getURL("http://www.youkaimura.org/nurika.htm":whistle:;

} else if(x == 62) {
nextFrame();
}else if(x==76){
frame=9;
gotoAndPlay(frame);
}
}
Key.addListener(keyListener);

On the first frame is this code:
keyListener = new Object();
keyListener.onKeyDown = function() {
x = Key.getAscii();
if(x == 65) {
nextFrame();
} else if(x == 88) {
nextFrame();
MyEffect_sound.start(0,0);
} else if(x == 32) {
nextFrame();
}else if(x==76){
frame = 14;
gotoAndPlay(frame);
}
}
Key.addListener(keyListener);

I don't get it.

#2 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 12 March 2007 - 11:00 PM

The problem is you can only run the onKeyDown function once... aswell as attaching a listener. Place this code on a new layer, on the first frame:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	var x:Number = Key.getAscii();
	if(this._currentframe == 14) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/ashima.htm";
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 15) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/nurika.htm");
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 1) {
		if(x == 65) {
			nextFrame();
		} else if(x == 88) {
			nextFrame();
			MyEffect_sound.start(0,0);
		} else if(x == 32) {
			nextFrame();
		} else if(x == 76) {
			frame = 14;
			gotoAndPlay(frame);
		}
	}
}
Key.addListener(keyListener);


#3 Nicodemus36Q

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 18 March 2007 - 06:31 PM

View PostBen, on Mar 12 2007, 11:00 PM, said:

The problem is you can only run the onKeyDown function once... aswell as attaching a listener. Place this code on a new layer, on the first frame:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	var x:Number = Key.getAscii();
	if(this._currentframe == 14) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/ashima.htm";
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 15) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/nurika.htm");
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 1) {
		if(x == 65) {
			nextFrame();
		} else if(x == 88) {
			nextFrame();
			MyEffect_sound.start(0,0);
		} else if(x == 32) {
			nextFrame();
		} else if(x == 76) {
			frame = 14;
			gotoAndPlay(frame);
		}
	}
}
Key.addListener(keyListener);

It doesn't work at all now. I don't know what to do.

#4 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 18 March 2007 - 07:44 PM

View PostNicodemus36Q, on Mar 19 2007, 10:31 AM, said:

View PostBen, on Mar 12 2007, 11:00 PM, said:

The problem is you can only run the onKeyDown function once... aswell as attaching a listener. Place this code on a new layer, on the first frame:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	var x:Number = Key.getAscii();
	if(this._currentframe == 14) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/ashima.htm";
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 15) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/nurika.htm");
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 1) {
		if(x == 65) {
			nextFrame();
		} else if(x == 88) {
			nextFrame();
			MyEffect_sound.start(0,0);
		} else if(x == 32) {
			nextFrame();
		} else if(x == 76) {
			frame = 14;
			gotoAndPlay(frame);
		}
	}
}
Key.addListener(keyListener);

It doesn't work at all now. I don't know what to do.
You sure you put it in correctly?

Actually, now that I think about it, the function can't work over a series of frames... Hmm I'll look into it a bit more :)

#5 Nicodemus36Q

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 19 March 2007 - 05:27 AM

View PostBen, on Mar 18 2007, 07:44 PM, said:

View PostNicodemus36Q, on Mar 19 2007, 10:31 AM, said:

View PostBen, on Mar 12 2007, 11:00 PM, said:

The problem is you can only run the onKeyDown function once... aswell as attaching a listener. Place this code on a new layer, on the first frame:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	var x:Number = Key.getAscii();
	if(this._currentframe == 14) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/ashima.htm";
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 15) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/nurika.htm");
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(this._currentframe == 1) {
		if(x == 65) {
			nextFrame();
		} else if(x == 88) {
			nextFrame();
			MyEffect_sound.start(0,0);
		} else if(x == 32) {
			nextFrame();
		} else if(x == 76) {
			frame = 14;
			gotoAndPlay(frame);
		}
	}
}
Key.addListener(keyListener);

It doesn't work at all now. I don't know what to do.
You sure you put it in correctly?

Actually, now that I think about it, the function can't work over a series of frames... Hmm I'll look into it a bit more :rolleyes:

Thanks for trying. I put the code the other way round so the first frame was first and nothing happened then I tried to put the frame with the second URL into a different scene but it made no difference. I'm completely stuck and I'm supposed to demo this in a few weeks.

#6 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 19 March 2007 - 06:06 AM

Well, I have a few weeks to figure this thing out... will most definately will help you in time. Just skip this part of your project for the time being and I'll figure this out for you :rolleyes:

#7 Nicodemus36Q

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 20 March 2007 - 04:52 AM

Alright well I suppose I'll create all the content for it and hope we can get it all working together at the end of the day.

#8 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 21 March 2007 - 03:36 PM

Wait, I figured it out. I was looking at a past thing I did, which involved keypresses. I was right, you can run them over frames, but the code I supplied you was wrong. I was using "this" before the _currentframe property, which returned nothing, since i was referring to the object, keyListener, by typing "this" inside one of it's handlers. So change it to:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	var x:Number = Key.getAscii();
	if(_parent._currentframe == 14) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/ashima.htm";
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(_parent._currentframe == 15) {
		if(x == 88) {
			getURL("http://www.youkaimura.org/nurika.htm");
		} else if(x == 62) {
			nextFrame();
		} else if(x == 76) {
			frame = 9;
			gotoAndPlay(frame);
		}
	} else if(_parent._currentframe == 1) {
		if(x == 65) {
			nextFrame();
		} else if(x == 88) {
			nextFrame();
			MyEffect_sound.start(0,0);
		} else if(x == 32) {
			nextFrame();
		} else if(x == 76) {
			frame = 14;
			gotoAndPlay(frame);
		}
	}
}
Key.addListener(keyListener);
I just changed "this" to "_parent", since that way it looks down to the _root, or the below level's frame.

#9 Nicodemus36Q

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 24 March 2007 - 05:19 AM

Nope ^_^

Wait I changed _parent to _root and now it semi-works. If I press L on the very first scene it goes to the menu screen and I can go between scrolls and it does open different web pages. Then I can press L again and it returns to an older screen but then it gets stuck. When testing it I pressed space to start with and that progressed a frame but then it got stuck.

Aha I've copied the part of the code for current frame one and changed it to current frame 2 and it looks like it might be sort of working.

Edited by Nicodemus36Q, 24 March 2007 - 06:54 AM.


#10 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 24 March 2007 - 06:08 PM

Are you running this over scenes? You can't do that. You will need to make a new listener for each scene. First rule of a Flash coder: NEVER use scenes ;) They cause way too much trouble when it comes to Actionscript. Anyway, if you need to keep the scenes, then do what I said just before; make a new listener for each scene. But don't name them the same. So scene one:
var keyListener:Object = new Object();
Scene two:
var keyListener2:Object = new Object();
Etc etc...

Hope you get it working ;)

#11 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 24 March 2007 - 09:53 PM

Just to expand on what Bed said, scenes were implemented for animators (which means no code would be used at all), but they can be slightly buggy if not used properly, or if you try to use code with them. You can now use a series of movieclips on the main timeline to achieve the same results, but without the bugs.

#12 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 25 March 2007 - 02:07 AM

View PostPax, on Mar 25 2007, 12:53 PM, said:

Just to expand on what Bed said...
Oh, I'm something people sleep on now, am I? ;)

#13 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 25 March 2007 - 08:46 AM

Wow, that was a nice typo :blink: N and D are a couple fingers apart...

Sorry bout that...I must have been a bit tired when I wrote that. I have one of those single track minds...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users