|
-
Another 1007 Null Object reference
Hey all,
I'm getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Website/frame1()[Website::frame1:19]
But the thing is, if I change the line numbers around in the website document class it still says that it's line number 19?
What's the deal with that? I'm a bit confused here!
Here is line 19
Code:
import flash.display.*;
Here is the entire code as well:
Code:
package {
import flash.display.*;
import FluidLayout.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import gs.*;
import gs.easing.*;
import fl.motion.easing.*;
import com.greensock.*;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
//import flash.text.TextFormat;
//import greensock.*;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
public class Website extends MovieClip {
public function Website() {this.addEventListener("addedToStage", initVar); }
/* Set the Scale Mode of the Stage */
private function initVar(e:Event){
******** this.removeEventListener("addedToStage", initVar);
//do your variable initilization, function calls, etc.
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
}
private var currentlyShowing:MovieClip=null;
public function showModalContent(clip:MovieClip):void {
if (currentlyShowing!=null) {
removeChild(currentlyShowing);
}
currentlyShowing=clip;
addChild(currentlyShowing);
}
public function removeModalContent():void {
if (currentlyShowing!=null) {
removeChild(currentlyShowing);
currentlyShowing=null;
}
}
}
}
-
That error looks like it is from frame script. What code do you have on frame 1?
-
On one fla - the main fla..
I have:
Line 19 would be the first line.. I read where when you load an swf externally, the stage doesn't exist the same way. Is this true?
Actionscript Code:
stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT;
-
Yes, that is true. When you load a swf into another swf, the loaded swf is instantiated as an object before it is put on the displaylist. This means that properties like root and stage are null until it has been added to the stage.
If those lines are in your loaded swf, it would cause the error.
-
I was looking at the document class the entire time, like why isn't this changing?
So, I guess it has to deal with the fullscreenEvent
Actionscript Code:
//FullScreen stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
//function to handle background image resize. function setBackground() { //var reg2 = stage.stageWidth / 2; //var reg1 = stage.stageHeight / 2; //bg_mc.x = reg2; //bg_mc.y = reg1; bg_mc.width=stage.stageWidth; bg_mc.height=stage.stageHeight; bg_mc.scaleX <= bg_mc.scaleY ? (bg_mc.scaleX = bg_mc.scaleY) : (bg_mc.scaleY = bg_mc.scaleX); musictxt_mc.x=stage.stageWidth-musictxt_mc.width*1.5; fullscreentxt_mc.x=stage.stageWidth-fullscreentxt_mc.width*4; bottomrightmints_mc.x=stage.stageWidth-bottomrightmints_mc.width; bottomrightmints_mc.y=stage.stageHeight-bottomrightmints_mc.height;
} setBackground();
function resizeHandler(event:Event):void { setBackground(); } //
-
If that is framescript in the fla which uses Website as a document class, then just delete those lines. You've already got them in the initVar function in Website.as.
If that code is for a different class or no document class, then you might want to put it inside a listener for ADDED_TO_STAGE.
It is also not really recommended that a loaded swf manipulate stage properties, since there is only one stage. If a loaded swf changes properties, it will stomp on anything that the loading swf has already done.
-
I think i'm getting closer here..
Actionscript Code:
if(stage != null) { init(); }
addEventListener(Event.ADDED_TO_STAGE, init);
function init(event:Event = null):void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT stage.addEventListener(Event.RESIZE, resizeHandler); }
/* //FullScreen stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler); */
//function to handle background image resize. function setBackground() { //var reg2 = stage.stageWidth / 2; //var reg1 = stage.stageHeight / 2; //bg_mc.x = reg2; //bg_mc.y = reg1; bg_mc.width=stage.stageWidth; bg_mc.height=stage.stageHeight; bg_mc.scaleX <= bg_mc.scaleY ? (bg_mc.scaleX = bg_mc.scaleY) : (bg_mc.scaleY = bg_mc.scaleX); musictxt_mc.x=stage.stageWidth-musictxt_mc.width*1.5; fullscreentxt_mc.x=stage.stageWidth-fullscreentxt_mc.width*4; bottomrightmints_mc.x=stage.stageWidth-bottomrightmints_mc.width; bottomrightmints_mc.y=stage.stageHeight-bottomrightmints_mc.height;
} setBackground();
function resizeHandler(event:Event):void { setBackground(); }
-
Still getting the error? I think it should be fixed.
You shouldn't need the if statement. Just putting the event listener on should be sufficient.
-
I'm still getting A error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Website/setBackground()[Website::frame1:43]
at Website/frame1()[Website::frame1:52]
Here is the code:
Actionscript Code:
stop(); //Import import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import gs.*; import gs.easing.*; import flash.text.TextField; import fl.motion.easing.*; import com.greensock.*; import FluidLayout.*;
//
if(stage != null) { init(); }
addEventListener(Event.ADDED_TO_STAGE, init);
function init(event:Event = null):void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT stage.addEventListener(Event.RESIZE, resizeHandler); }
/* //FullScreen stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler); */ bg_mc=new mc_bg();
//function to handle background image resize. function setBackground() { //var reg2 = stage.stageWidth / 2; //var reg1 = stage.stageHeight / 2; //bg_mc.x = reg2; //bg_mc.y = reg1; bg_mc.width=stage.stageWidth; bg_mc.height=stage.stageHeight; bg_mc.scaleX <= bg_mc.scaleY ? (bg_mc.scaleX = bg_mc.scaleY) : (bg_mc.scaleY = bg_mc.scaleX); musictxt_mc.x=stage.stageWidth-musictxt_mc.width*1.5; fullscreentxt_mc.x=stage.stageWidth-fullscreentxt_mc.width*4; bottomrightmints_mc.x=stage.stageWidth-bottomrightmints_mc.width; bottomrightmints_mc.y=stage.stageHeight-bottomrightmints_mc.height;
} setBackground();
function resizeHandler(event:Event):void { setBackground(); }
also, here is my document class
Actionscript Code:
package {
import flash.display.*; import FluidLayout.*; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import gs.*; import gs.easing.*; import fl.motion.easing.*; import com.greensock.*; import flash.text.AntiAliasType; import flash.text.TextField; import flash.text.TextFieldAutoSize; //import flash.text.TextFormat; //import greensock.*; import flash.events.MouseEvent; import flash.display.*; import flash.events.*; import flash.net.URLRequest;
public class Website extends MovieClip {
public function Website() {this.addEventListener("addedToStage", initVar); } /* Set the Scale Mode of the Stage */ private function initVar(e:Event){ ******** this.removeEventListener("addedToStage", initVar); //do your variable initilization, function calls, etc. stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT;
/* Add the symbols to stage var bg = new Background(); addChild(bg); */ //// var top = new Top(); // //addChild(top);
//var toprightoption = new toprightoption(); //addChild(toprightoption);
//var middle = new Middle(); //addChild(middle); ////var btmrightfooter = new btmrightfooter(); ////addChild(btmrightfooter);
/* Apply the alignment to the background var bgParam = { x:0, y:0, offsetX: 0, offsetY: 0 } new FluidObject(bg,bgParam); */ /* Apply the alignment to the top */ ///// var topParam = { //// x:0, //// y:0, //// offsetX:0, //// offsetY:0 //// }; ////new FluidObject(top,topParam);
/* Apply the alignment to the toprightoption */ //// var toprightoptionParam = { //// x:1, //// y:0, //// offsetX: -toprightoption.width - 20, //// offsetY: 20 //// }; ////new FluidObject(toprightoption,toprightoptionParam);
/* Apply the alignment to the content var middleParam = { x:0.5, y:0.5, offsetX: -middle.width/2, offsetY: -middle.height/2 } new FluidObject(middle,middleParam); */ /* Apply the alignment to the btmrightfooter */ //// var btmrightfooterParam = { //// x:1, //// y:1, //// offsetX: -btmrightfooter.width - 10, //// offsetY: -btmrightfooter.height -10 //// }; //// new FluidObject(btmrightfooter,btmrightfooterParam); }
private var currentlyShowing:MovieClip=null;
public function showModalContent(clip:MovieClip):void { if (currentlyShowing!=null) { removeChild(currentlyShowing); } currentlyShowing=clip; addChild(currentlyShowing); }
public function removeModalContent():void { if (currentlyShowing!=null) { removeChild(currentlyShowing); currentlyShowing=null; }
}
}
}
I commented out ALOT in the class..
Last edited by aesthetics7; 02-10-2010 at 06:02 PM.
-
Yeah, you are executing setBackground before it has been added to the displaylist, so stage is null.
Move the call to setBackground() into the ADDED_TO_STAGE listener.
-
-
No, line 52. The one that is executed immediately.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|