I have a package (XMLThumbLoader) that loads thumbnails and is supposed to import a scroller class(DSIScroller).
The thumbloader works fine, but when I try to scroll the thumbsContainer movie clip, I get “Error #1009 Cannot acces a property or method of a null object reference”.
Notice that I instantiated the DSIScroller class near the end of the main package instead of underneath the import DSIScroller command. By doing this, my thumbnails show up. If I place the instantiation right under the import command, no thumbs show…
I believe the issue is with the dynamically created movie clip: thumbsContainer.
Here is the main package (XMLThumbLoader)
package {
import flash.xml.*;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.Event;
import flash.text.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class XMLThumbLoader extends MovieClip{
public function XMLThumbLoader(){
import DSIScroller;
var thumb_width:Number;
var thumb_height:Number;
var thumbs_x:Number;
var thumbs_y:Number;
var my_videos:XMLList;
var my_total:Number;
var thumbsContainer:Sprite;
var thumbs:Sprite;
var titles:Sprite;
var vidDesc:Sprite;
var vidLink:Sprite;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load (new URLRequest("playlist.xml"));
myXMLLoader.addEventListener (Event.COMPLETE, processXML);
var videoFont:Font = new VidDescFont();
function processXML (e:Event):void {
var myXML:XML = new XML(e.target.data);
thumb_width = myXML.@THUMB_WIDTH;
thumb_height = myXML.@THUMB_HEIGHT;
thumbs_x = myXML.@THUMBS_X;
thumbs_y = myXML.@THUMBS_Y;
my_videos = myXML.vid;
my_total = my_videos.length();
makeContainers ();
callThumbs ();
}
function makeContainers ():void {
thumbsContainer = new Sprite();
addChild (thumbsContainer);
thumbs = new Sprite();
//thumbs.addEventListener (MouseEvent.CLICK, playClicked);
thumbs.addEventListener (MouseEvent.MOUSE_OVER, onOver);
thumbs.addEventListener (MouseEvent.MOUSE_OUT, onOut);
thumbs.x = thumbs_x;
thumbs.y = thumbs_y;
thumbs.buttonMode = true;
thumbsContainer.addChild (thumbs);
titles = new Sprite();
titles.x = thumbs_x;
titles.y = thumbs_y;
vidDesc = new Sprite();
vidDesc.x = thumbs_x;
vidDesc.y = thumbs_y;
thumbsContainer.addChild (titles);
thumbsContainer.addChild (vidDesc);
thumbsContainer.mask=contentMask;
}
function callThumbs ():void {
for (var i:Number = 0; i < my_total; i++) {
var thumb_url = my_videos*.@thumb;
var thumb_loader = new Loader();
thumb_loader.name = i;
thumb_loader.load (new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
thumb_loader.y = (thumb_height+10)*i;
thumb_loader.alpha=0.5; //set initial thumb alpha
var thumb_title = my_videos*.@vidTitle;
var title_txt:TextField = new TextField();
title_txt.antiAliasType = AntiAliasType.ADVANCED;
title_txt.text = thumb_title;
title_txt.wordWrap = true;
title_txt.embedFonts = true;
title_txt.y = thumb_loader.y+4;
title_txt.x = thumb_width + 7;
title_txt.width = 180;
titles.addChild (title_txt);
var desc_var = my_videos*.@desc;
var desc_txt:TextField = new TextField();
desc_txt.antiAliasType = AntiAliasType.ADVANCED;
desc_txt.text = desc_var;
desc_txt.wordWrap = true;
desc_txt.embedFonts = true;
desc_txt.y = (thumb_loader.y+vtf.size)+10;//make sure description text is set below title txt using title size plus a "cushion" of 8 pixels
desc_txt.x = thumb_width + 7;
desc_txt.width = 180;
vidDesc.addChild (desc_txt);
//add thumbTile
var thumbTile:Tile = new Tile();
thumbTile.y = (thumb_height+10)*i;
thumbTile.height=thumb_height;
thumbTile.width=(desc_txt.width+thumb_width+15);//ensures tile graphic width does not fall short of description text
thumbsContainer.addChild(thumbTile);
}
track.y = contentMask.y;
handler.y = track.y + 10;
thumbsContainer.x = track.x -thumbsContainer.width- 25;
thumbsContainer.y=track.y - thumbs_y+2;
}
function thumbLoaded (e:Event):void {
var my_thumb:Loader = Loader(e.target.loader);
thumbs.addChild (my_thumb);
}
var sc:DSIScroller =new DSIScroller(handler, track, thumbsContainer);
addChild(sc);
}//end function
}//end class
}//end package
The imported scroller (DSIScroller)
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.Event;
import flash.text.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import gs.TweenLite;
import fl.motion.easing.*;
import fl.transitions.*;
import fl.transitions.easing.*;
public class DSIScroller extends MovieClip{
public function DSIScroller(handler:MovieClip, track:MovieClip, thumbsContainer:Sprite){
/*** Scrollbar ***/
//on click, start scrolling
function startScroll(event:MouseEvent):void {
handler.startDrag(false, new Rectangle(track.x, track.y+10, 0, track.height-handler.height-20));
TweenLite.to(thumbsContainer, 0.5, {y:"0", ease:Regular.easeOut});
stage.addEventListener(Event.ENTER_FRAME, scrollGo);
}
//on mouse up, stop scrolling
function stopScroll(event:MouseEvent):void {
stopDrag();
stage.removeEventListener(Event.ENTER_FRAME, scrollGo);
}
//move thumbsContainer
function scrollGo(event:Event):void { //90 determines how far up last thumb will place
TweenLite.to(thumbsContainer, 0.5, {y:Math.round(track.y-(thumbsContainer.height-(track.height+110-handler.height))*((handler.y-track.y-10)/(track.height-20-handler.height))), ease:Regular.easeOut});
}
//*************** Events ***************//
handler.buttonMode=true;
handler.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
}//end DSIScroller function
}//end DSIScroller
}//end package
Sorry for the length. Any help would be appreciated.