TypeError: Error #1009 (Help Please?)
I'm new with the whole ActionScripting Thing. :( So I truly appreciate it if someone can explain to me as simply as possible. :D
I keep getting the errors below when I click to go to another page. Please help me out if I'm doing something wrong. ^^
TypeError: Error #1009: Cannot access a property or method of a null object reference. at FlashDoc_fla::MainTimeline/followBall_a() TypeError: Error #1009: Cannot access a property or method of a null object reference. at FlashDoc_fla::MainTimeline/rotate_a()
Codes are as follow...
stage.addEventListener(Event.ENTER_FRAME,rotate_a);
function rotate_a (e:Event){
var theX:int = mouseX - eye_ball_icon.x;
var theY:int = (mouseY - eye_ball_icon.y) * -1;
var angle = Math.atan(theY/theX)/(Math.PI/180);
if (theX<0开发者_C百科) {
angle += 180;
}
if (theX>=0 && theY<0) {
angle += 360;
}
eye_text.text = angle;
eye_ball_icon.rotation = (angle*-1) + 90;
}
stage.addEventListener(Event.ENTER_FRAME,followBall_a);
function followBall_a(event:Event):void {
var dx:int = eye_ball_icon.x - mouseX;
eye_ball_icon.x -= dx / 20;
eye_ball_icon.y=530;
if (eye_ball_icon.x < 150){eye_ball_icon.x = 150};
if (eye_ball_icon.x > 850){eye_ball_icon.x = 850};
}
stop();
about_icon.addEventListener(MouseEvent.CLICK,iconpage);
function iconpage(event:MouseEvent) { gotoAndPlay(3); }
works_icon.addEventListener(MouseEvent.CLICK,workspage);
function workspage(event:MouseEvent) { gotoAndPlay(4); }
contact_icon.addEventListener(MouseEvent.CLICK,contactpage);
function contactpage(event:MouseEvent) { gotoAndPlay(5); }
Try this rotate_a method:
function rotate_a (e:Event){
if(currentFrame==1){
var theX:int = mouseX - eye_ball_icon.x;
var theY:int = (mouseY - eye_ball_icon.y) * -1;
var angle = Math.atan(theY/theX)/(Math.PI/180);
if (theX<0) {
angle += 180;
}
if (theX>=0 && theY<0) {
angle += 360;
}
eye_text.text = angle;
eye_ball_icon.rotation = (angle*-1) + 90;
}}
It checks to see if you are on frame 1 before trying to do anything with the objects on frame 1. I'm assuming that you have this code in the first frame, and that eye_text and eye_ball_icon are on the first frame.
精彩评论