dwickwire
February 26th, 2009, 04:41 PM
Hi all,
I am getting this error with my code when I try to resize my stage
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main_fla::MainTimeline/resizeStageHandler()
This happens only if the slideshow is being used and I resize the browser. My URL is http://timtabstudios.com/flash/main.html
I just read somewhere that it could be caused from calling the root...
I do that from my menu bar calling the root to open the slideshow movie clip and play the according gallery...
When my button is clicked it runs this code...
MovieClip(root).gotoAndStop(3); thenMovieClip(parent).slideshow.gotoAndPlay("weddings");
Note: I have a 3 timeline fla file. All of them have the menu bar, logo and background in common...
* first frame for my preloader
* second for the content (about/rates/contact)
* third frame for slideshows
Any help would be grately appreciated.
Here is my code...
stop();
// Import the API Libraries to allow tweening effects for the menu bar and logo movie clips
import fl.transitions.Tween;
import fl.transitions.easing.*;
// Aligns everything to the top left side
stage.align = StageAlign.TOP_LEFT;
// Disables the movie from scaling
stage.scaleMode = StageScaleMode.NO_SCALE;
back.width = stage.stageWidth;
back.scaleY = back.scaleX;
if(stage.stageHeight > back.height)
{
back.height = stage.stageHeight;
back.scaleX = back.scaleY;
}
// POSITIONING CODE
logo_girl.x = stage.stageWidth/2;
logo_girl.y = stage.stageHeight/2;
//info3.x = info1.x + (info1.width/2) + 20 + info3.width/2;
pages.x = stage.stageWidth/2;
pages.y = stage.stageHeight/2;
// TWEENING CODE
var moveX = (stage.stageWidth/2); // sets location of the menu bar to middle of the x axis
var moveY = (stage.stageHeight) - (menu.height/5); //sets the menu bar just above the bottom
var moveXTween = new Tween(menu,"x",Strong.easeOut,menu.x,moveX,1,true);
var moveYTween = new Tween(menu,"y",Strong.easeOut,menu.y,moveY,1,true);
var move_logoX = stage.stageWidth - (stage.stageWidth/4);
var move_logoY = (stage.stageHeight/8) - (timtab_logo.height);
var move_logoXTween:Tween;
var move_logoYTween:Tween;
move_logoXTween = new Tween(timtab_logo,"x",Strong.easeOut,timtab_logo.x,move_logoX,1,true);
move_logoYTween = new Tween(timtab_logo,"y",Strong.easeOut,timtab_logo.y,move_logoY,1,true);
// SCALING CODE
logo_girl.scaleX = back.scaleX;
logo_girl.scaleY = back.scaleX;
if(stage.stageWidth >= 800)
{
menu.scaleX = back.scaleX;// mc2 scales with mc1
menu.scaleY = back.scaleX;// proportional scaling
timtab_logo.scaleX = back.scaleX;
timtab_logo.scaleY = back.scaleX;
pages.scaleX = menu.scaleX;// pages scales with background
pages.scaleY = menu.scaleX;// proportional scaling for the pages is set here
}
// Listens to if the browser if resized and responds accordingly
this.stage.addEventListener(Event.RESIZE, resizeStageHandler);
function resizeStageHandler(event:Event):void {
// trace("working");
// Same code as above...
back.width = stage.stageWidth;
back.scaleY = back.scaleX;
if(stage.stageHeight > back.height)
{
back.height = stage.stageHeight;
back.scaleX = back.scaleY;
}
// POSITIONING CODE
logo_girl.x = stage.stageWidth/2;
logo_girl.y = stage.stageHeight/2;
pages.x = stage.stageWidth/2;
pages.y = stage.stageHeight/2;
// TWEENING CODE
moveX = (stage.stageWidth/2); // sets location of the menu bar to middle of the x axis
moveY = (stage.stageHeight) - (menu.height/5); // sets the menu bar just above the bottom
moveXTween = new Tween(menu,"x",Strong.easeOut,menu.x,moveX,1,true);
moveYTween = new Tween(menu,"y",Strong.easeOut,menu.y,moveY,1,true);
move_logoX = stage.stageWidth - (stage.stageWidth/4);
move_logoY = (stage.stageHeight/8) - (timtab_logo.height);
move_logoXTween:Tween;
move_logoYTween:Tween;
move_logoXTween = new Tween(timtab_logo,"x",Strong.easeOut,timtab_logo.x,move_logoX,1,true);
move_logoYTween = new Tween(timtab_logo,"y",Strong.easeOut,timtab_logo.y,move_logoY,1,true);
// SCALING CODE
logo_girl.scaleX = back.scaleX;
logo_girl.scaleY = back.scaleX;
if(stage.stageWidth >= 800)
{
menu.scaleX = back.scaleX;// mc2 scales with mc1
menu.scaleY = back.scaleX;// proportional scaling
timtab_logo.scaleX = back.scaleX;
timtab_logo.scaleY = back.scaleX;
pages.scaleX = menu.scaleX;// pages scales with background
pages.scaleY = menu.scaleX;// proportional scaling for the pages is set here
}
}
mathew.er
March 3rd, 2009, 08:24 PM
Try to debug the swf. On a PC ctrl+shift+enter, on a Mac cmd+shift+enter and resize the window, it should stop at the line where the error occured. It's imposible for anyone from us to find the error as it's because some of the objects that you are accessing in resizeStageHandler doesn't exist in that scope.
When it identifies the line... let's say it's
pages.x = stage.stageWidth/2;now put trace actrions for both pages and stage, e. g.
trace ( pages ) if it traces out null or something like that, you've found the problem :)
dwickwire
March 6th, 2009, 11:15 AM
First of all thank you so much for your post. I resolved the error by putting the two movieclips on the same timeline and then making one or the other invisble when it was running. So on Pages, slideshow is inivible and I set pages visible and visa versa. Before I was trying to call the slideshow or pages on differnet frames ( i think had pages on 2 and slideshow on 3) but that didn't work I don't know why. But simply making them on the same frame worked!
However I do have the exact same Error #1009 with a different area in my website.
... I tried to trace the issue but that hasn't helped yet.
BTW my site url has changed... it is www.timtabstudios.com/flash/ (http://www.timtabstudios.com/flash/) (until I fix this problem)
NOTE: To simulate the error...
1) USE IE7 go to my website... http://www.timtabstudios.com/flash/
(http://www.timtabstudios.com/flash/)2) go into any slideshow, then go directly into another slideshow and resize the browser
and you'll see... (i renamed resizeStageHandler to StageHandler)
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at slickgallery::SlickGallery/StageHandler()
This only happens AFTER you have already entered one gallery, so the code is running properly on the first call of the AS file but then if you recall the AS file from another gallery it gives the problem when you resize.
I have tried to trace the stage at the resizeStageHandler and the left and right arrow but they are not null.
----------
BTW here is the code that runs for each gallery movie clip
/* This is the basic code in each gallery's movie clip to call the AS file and images */
import slickgallery.SlickGallery;
var s:SlickGallery = new SlickGallery("enagements_gallery.xml", 0x000000);
addChild(s);
Here is the SlickGallery code that is loading the slideshows...
// SlickGallery AS File for my slideshow
package slickgallery {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.*;
import caurina.transitions.*;
import flash.text.TextField;
import flash.text.TextFormat;
public class SlickGallery extends MovieClip{
private var _skinColor:uint;
private var _xmlRequest:URLRequest;
private var _xmlLoader:URLLoader;
private var _imageLoader:Loader;
private var _imageContainer:MovieClip = new MovieClip();
private var _loadingIndicator:MovieClip;
private var _leftArrowLoader:Loader;
private var _leftArrow:MovieClip;
private var _rightArrowLoader:Loader;
private var _rightArrow:MovieClip;
private var _mask:MovieClip;
private var _background:MovieClip;
private var _textbox_background:MovieClip;
private var _textbox:TextField;
private var _activeImage:Array = new Array();
private var _defaultWidth:Number = 500;
private var _defaultHeight:Number = 300;
private var _textboxHeight:Number = 40;
private var _padding:Number = 18;
private var _imageIndex:int = 0;
private var _textColor:uint = 0xFFFFFF;
private var _textFormat:TextFormat;
private var _data:XML;
//Contructor
public function SlickGallery(xmlFile:String="images.xml", skinColor:uint=0x000000) {
this._skinColor = skinColor;
this._xmlRequest = new URLRequest(xmlFile);
this._xmlLoader = new URLLoader(_xmlRequest);
this._xmlLoader.addEventListener(Event.COMPLETE, this.init);
this._xmlLoader.addEventListener(ProgressEvent.PRO GRESS, this.xml_PROGRESS);
this._xmlLoader.addEventListener(IOErrorEvent.IO_E RROR, this.xml_IO_ERROR);
}
private function init(e:Event):void {
//background
this._background = new MovieClip();
this._background.graphics.beginFill(this._skinColo r, 0.5);
this._background.graphics.drawRect(-(this._defaultWidth/2), -(this._defaultHeight/2), this._defaultWidth, this._defaultHeight);
this._background.graphics.endFill();
this.addChild(this._background);
//this._background.x = (this.x + this._background.width / 2);
//this._background.y = (this.y + this._background.height / 2);
//mask
this._mask = new MovieClip();
this._mask.graphics.beginFill(this._skinColor);
this._mask.graphics.drawRect(-(this._defaultWidth/2)+this._padding, -(this._defaultHeight/2)+this._padding, this._defaultWidth-this._padding*2, this._defaultHeight-this._padding*2);
this._mask.graphics.endFill();
this.addChild(this._mask);
//this._mask.x = (this.x + this._mask.width / 2);
//this._mask.y = (this.y + this._mask.height / 2);
//Image container
this.addChild(this._imageContainer);
//arrows
this._leftArrowLoader = new Loader();
this._leftArrowLoader.load(new URLRequest("images/left_arrow.png"));
this._leftArrowLoader.contentLoaderInfo.addEventLi stener(Event.COMPLETE, this.positionLeftArrow);
this._leftArrow = new MovieClip();
this._leftArrow.name = "Left Arrow";
this._leftArrow.addChild(this._leftArrowLoader);
this.addChild(this._leftArrow);
this._leftArrow.useHandCursor = true;
this._leftArrow.buttonMode = true;
this._leftArrow.addEventListener(MouseEvent.CLICK, this.leftArrow_CLICK);
//right arrow
this._rightArrowLoader = new Loader();
this._rightArrowLoader.load(new URLRequest("images/right_arrow.png"));
this._rightArrowLoader.contentLoaderInfo.addEventL istener(Event.COMPLETE, this.positionRightArrow);
this._rightArrow = new MovieClip();
this._rightArrow.name = "Right Arrow";
this._rightArrow.addChild(this._rightArrowLoader);
this._rightArrow.x = this._background.width;
this.addChild(this._rightArrow);
this._rightArrow.useHandCursor = true;
this._rightArrow.buttonMode = true;
this._rightArrow.addEventListener(MouseEvent.CLICK , this.rightArrow_CLICK);
// Right arrow
//text background
this._textbox_background = new MovieClip();
this._textbox_background.graphics.beginFill(this._ skinColor,0.6);
this._textbox_background.graphics.drawRect(0,0, this._background.width-this._padding*2, this._textboxHeight);
this._textbox_background.graphics.endFill();
this.addChild(this._textbox_background);
this._textbox_background.x = -(this._background.width / 2) + this._padding;
this._textbox_background.y= this._background.height / 2 - this._textboxHeight - this._padding;
//textbox format
this._textFormat = new TextFormat();
this._textFormat.font = "Arial";
this._textFormat.size = 12;
this._textFormat.color = this._textColor;
//textbox
this._textbox = new TextField();
this._textbox.antiAliasType = "advanced";
this._textbox.autoSize = "left";
this._textbox.embedFonts = true;
this._textbox.selectable = false;
this._textbox.wordWrap = true;
this._textbox.width = this._background.width - this._padding*2;
this._textbox.x = -(this._background.width / 2) + this._padding;
this._textbox.y = this._background.height / 2 - this._textboxHeight - this._padding;
this._textbox.text = "asdfasdf";
this._textbox.setTextFormat(this._textFormat);
this.addChild(this._textbox);
//loading indicator
this._loadingIndicator = new MovieClip();
this._loadingIndicator.graphics.beginFill(0xFFFFFF , 1);
this._loadingIndicator.graphics.drawRect(0, 0, 1, 2);
this._loadingIndicator.graphics.endFill();
this._loadingIndicator.alpha = 0;
this._loadingIndicator.x = (this._background.x - this._background.width / 2) + this._padding;
this._loadingIndicator.y=(this._background.height / 2) - this._loadingIndicator.height - this._padding;
this.addChild(this._loadingIndicator);
this.initEventListeners();
//loading data
this._data = new XML(e.currentTarget.data);
if (this._data.image.length() > 0) {
this.loadImage(0);
}
}
private function initEventListeners() {
//addEventListener(Event.ADDED_TO_STAGE, StageHandler, false, 0, true);
trace("Stage is: " + this.stage);
stage.addEventListener(Event.RESIZE, resizeStageHandler);
}
private function removeEventListeners() {
//stage.removeEventListener(Event.RESIZE, StageHandler);
}
private function resizeStageHandler(event:Event):void
{
this._leftArrow.x = (- stage.stageWidth / 2);
this._rightArrow.x = stage.stageWidth / 2 - this._rightArrow.width;
}
private function imageContainer_ROLL_OVER(e:MouseEvent):void {
Tweener.addTween(this._textbox, { alpha:1, time:0.5, onStart:function():void { this.visible = false } } );
Tweener.addTween(this._textbox_background, { alpha:1, time:0.5, onStart:function():void{this.visible=false} });
Tweener.addTween(this._leftArrow, { alpha:1, time:0.5, onStart:function():void{this.visible=true} } );
Tweener.addTween(this._rightArrow, { alpha:1, time:0.5, onStart:function():void{this.visible=true} } );
}
private function imageContainer_ROLL_OUT(e:MouseEvent):void {
Tweener.addTween(this._textbox, { alpha:0, time:0.3, onComplete:function():void { this.visible = false; } } );
Tweener.addTween(this._textbox_background, { alpha:0, time:0.3,onComplete:function():void { this.visible = false; } } );
Tweener.addTween(this._leftArrow, { alpha:0, time:0.3, onComplete:function():void { this.visible = false; } } );
Tweener.addTween(this._rightArrow, { alpha:0, time:0.3, onComplete:function():void { this.visible = false; }} );
}
private function positionLeftArrow(e:Event):void {
//trace("Left Arrow Image Loaded");
//this._leftArrow.x = (this._background.x - this._background.width / 2) + 5;
//this._leftArrow.y = this._background.y - this._leftArrow.height / 2;
}
private function positionRightArrow(e:Event):void {
//trace("Right Arrow Image Loaded");
//trace("Right Arrow x pos: "+this._rightArrow.x);
//trace("SW"+stage.stageWidth);
//trace("PSW"+parent.stage.stageWidth);
//this._rightArrow.x = this._background.width/2 + this._rightArrow.width;
//this._rightArrow.y = this._background.y - this._rightArrow.height / 2;
}
private function xml_PROGRESS(e:ProgressEvent):void {
trace("XML Loading loaded:" + e.bytesLoaded + " total: " + e.bytesTotal);
}
private function xml_IO_ERROR(e:IOErrorEvent):void {
trace("ioErrorHandler: " + e);
}
private function showControls():void {
Tweener.addTween(this._leftArrow, { alpha:1, delay:0.3,time:0.5 , onStart:function():void { this.visible = true; }} );
Tweener.addTween(this._rightArrow, { alpha:1,delay:0.3, time:0.5, onStart:function():void { this.visible = true; } } );
Tweener.addTween(this._textbox_background, { alpha:1, delay:0.3,time:0.3, onStart:function():void { this.visible = false; } } );
Tweener.addTween(this._textbox, { alpha:1, delay:0.3,time:0.5, onStart:function():void { this.visible = false; }} );
}
private function loadImage(imageIndex:Number = 0):void {
//trace(this._data.image[imageIndex].attribute("filename"));
this._imageIndex = imageIndex;
//initializing the loading indicator
this._loadingIndicator.width = 1;
this.removeEventListeners();
Tweener.addTween(this._loadingIndicator, { time:0.3, alpha:1 } );
this._leftArrow.visible = false;
this._rightArrow.visible = false;
this._textbox.alpha = 0;
this._textbox_background.alpha = 0;
this._imageLoader = new Loader();
this._imageLoader.load(new URLRequest(this._data.image[imageIndex].attribute("filename")));
this._imageLoader.contentLoaderInfo.addEventListen er(ProgressEvent.PROGRESS, this.image_PROGRESS);
this._imageLoader.contentLoaderInfo.addEventListen er(Event.COMPLETE, this.image_COMPLETE);
}
private function image_PROGRESS(e:ProgressEvent):void {
var percentage:Number = 100 / (e.bytesTotal / e.bytesLoaded);
trace("Loading..." + percentage);
this._loadingIndicator.width = percentage * ((this._background.width-this._padding*2) / 100);
}
private function image_COMPLETE(e:Event):void {
this._mask.width = 50;
this._mask.height = 50;
Tweener.addTween(this._loadingIndicator, { alpha:0, time:0 } );
this._textbox.text = this._data.image[this._imageIndex].attribute("text");
this._textbox.setTextFormat(this._textFormat);
trace("Image Loaded");
var image:MovieClip = new MovieClip();
image.alpha = 0;
image.addChild(this._imageLoader);
this._imageContainer.addChild(image);
image.name = "Image" + this._imageIndex;
image.x = -image.width / 2;
image.y = -image.height / 2;
image.mask = this._mask;
this.resizeAndMove(image.width, image.height);
if (this._activeImage[0] != null && this._activeImage[0]!=undefined){
Tweener.addTween(this._activeImage, { alpha:0, time:0.4, onComplete:function():void { _imageContainer.removeChild(_activeImage[0]);}} );
}
Tweener.addTween(image, { time:0.5, alpha:1, onComplete:function():void { _activeImage[0] = image; showControls(); initEventListeners(); } } );
}
private function resizeAndMove(width:Number, height:Number):void {
this._leftArrow.x = (- stage.stageWidth) / 2;
this._rightArrow.x = stage.stageWidth / 2 - this._rightArrow.width;
this._textbox.x = -width / 2;
this._textbox.y = height / 2 - this._textboxHeight;
this._textbox_background.x = -width / 2;
this._textbox_background.y = height / 2 - this._textboxHeight;
this._loadingIndicator.x = -width / 2;
this._loadingIndicator.y = height / 2 - this._loadingIndicator.height;
this._loadingIndicator.x = -width / 2;
Tweener.addTween(this._background, {width:width+this._padding*2, height:height+this._padding*2, time:0.5, transition:"easeOutBack" } );
Tweener.addTween(this._mask, { width:width, height:height, time:1, transition:"easeOutExpo" });
Tweener.addTween(this._textbox_background, { alpha:0, width:width, time:0, transition:"easeOutBack" } );
Tweener.addTween(this._textbox, { alpha:0,width:width, time:0, transition:"easeOutBack" });
}
private function leftArrow_CLICK(e:MouseEvent):void {
trace(e.currentTarget.name + " clicked");
if (this._imageIndex > 0) {
this._imageIndex -= 1;
} else {
this._imageIndex = this._data.image.length() - 1;
}
this.loadImage(this._imageIndex);
}
private function rightArrow_CLICK(e:MouseEvent):void {
trace(e.currentTarget.name + " clicked");
if (this._imageIndex < this._data.image.length() - 1) {
this._imageIndex += 1;
} else {
this._imageIndex = 0;
}
this.loadImage(this._imageIndex);
}
}
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.