Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Preload images for this code

Explorer ,
Jun 12, 2010 Jun 12, 2010

I'm working on an AS3 flash file that was created by another person, who I don't have access to for help, unfortunately.

The file loads a series of thumbnail images from an xml file into a movieclip, adds that to a second movieclip container, then adds that to the stage. This all works beautifully when run locally, but when uploaded to an internet server, some of the thumbnail image items are blank - apparently because it doesn't load them fast enough. The more the page is reloaded on the internet, the more of the images appear. I've already confirmed that the image names are correct and the images are there, so have narrowed it down to the loading speed.c

As such, what I like to do is add an event listener to only add the movieclip to the container once it has successfully loaded its image, but I'm not sure how to go about this for a movieclip.

The code that adds the image to the clip then the clip to the container is:

for (var i:int = 0; i < imageLength; i++) {

var thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

this.footerThumbs.scroller.container.addChild(thumbItem);

}
I believe I need to add an event listener to 'thumbitem' and only run the next line once it is successful, but I'm not sure what to listen for; if anyone can help?

TOPICS
ActionScript
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 12, 2010 Jun 12, 2010

1. Create a public variable e.g. assetsToLoad:uint in your main document class (or on main timeline) and assign to this variable the number of thumbs to load - it can be read from xml file, assetsToLoad = picsList.length() or something similar.

2. Add Event.COMPLETE listener to loader instance inside ThumbItem class. The handler of this event will decrease assetsToLoad variable:

function loadHandler(e:Event):void

{

    var _root:Object = this.root;

     _root.assetsToLoad--;

     if (_root.assetsToLoad == 0)

     {

          _root.addImagesToClip();

     }

}

3. Function addImagesToClip() is public, defined in main document class (or main timeline) and it adds all images to the clip and so on, using a loop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 12, 2010 Jun 12, 2010

I'm not quite sure I'm understanding what you're getting at here.

ThumbItem is not a class with any associated code of its own, it's a movieclip object. It doesn't have a loader instance.

When I add an event listener to the lines I showed previously, like this:

for (var i:int = 0; i < imageLength; i++) {

var thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

thumbItem.addEventListener(Event.COMPLETE, addThumb);

function addThumb ():void {

this.footerThumbs.scroller.container.addChild(thumbItem);

}

}

I get this error:
RangeError: Error #2006: The supplied index is out of bounds.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2010 Jun 13, 2010

It won't work like this. Event.COMPLETE is dispatched when the file has completed loading. It is to be added to contentLoaderInfo of a Loader.

Your code (line pasted below) obviously says that ThumbItem is a class, which extends MovieClip class - otherwise you couldn't assign it to the var typed as MovieClip. It also takes two arguments (including a path to file) so there must be some code associated with it.

var thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

Do you have ThumbItem as a symbol in the library? If yes, rightclick on it there and choose Properties and in Linkage section you should see names of one or two classes - Class and Base Class. Next to the names are buttons to edit class definition that will open the class file. We are interested in the othar than MovieClip class Paste it's code and we will see what's it about.

If there is no ThumItem symbol in library try other way to find the source of it's class - in this case it probably will be in a file called ThumbItem.as

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

Thank you - you're right of course, the code is there, along with an event listener for the image load.

package com.fladev.template.Gallery

{

import flash.display.Loader;

import flash.display.MovieClip;

import flash.net.URLRequest;

import flash.text.TextField;

import flash.events.MouseEvent;

import flash.text.TextFieldAutoSize;

import caurina.transitions.Tweener;

import flash.events.Event;

import flash.events.ProgressEvent;

import caurina.transitions.Tweener;

public class ThumbItem extends MovieClip

{

public var num:Number;

public var cover:String;

public var title:String;

public var titleColor:String;

public var colorOver:String;

public var colorOut:String;

private var loader:Loader;

public function ThumbItem(num:Number, cov:String) {

this.num = num;

this.cover = cov;

//trace(this.cover + "cover");

this.buttonMode = true;

this.mouseChildren  = false;

loader = new Loader();

this.loader.load(new URLRequest(cov));

this.thumb.addChild(this.loader);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadedComplete);

this.x = num * 65;

this.addEventListener(MouseEvent.ROLL_OVER, over);

this.addEventListener(MouseEvent.ROLL_OUT, out);

}

private function over(e:MouseEvent):void {

e.target.border.gotoAndPlay("over");

}

private function out(e:MouseEvent):void {

e.target.border.gotoAndPlay("out");

}

private function imageLoadedComplete(e:Event):void {

try {

e.target.content.alpha = 0;

Tweener.addTween(e.target.content, { alpha:1, time:1, transition:"easeOutSine" } );

e.target.content.smoothing = true;

} catch (e:Error) { };

}

public function selected() {

this.enabled = false;

this.mouseEnabled = false;

this.border.gotoAndStop(14);

this.removeEventListener(MouseEvent.ROLL_OVER, over);

this.removeEventListener(MouseEvent.ROLL_OUT, out);

}

public function deselected() {

this.enabled = true;

this.mouseEnabled = true;

this.border.gotoAndStop(1);

this.addEventListener(MouseEvent.ROLL_OVER, over);

this.addEventListener(MouseEvent.ROLL_OUT, out);

}

}

}

So now I'm back to wondering why this works perfectly when I run it locally, but does not load all of the thumbnail items when I put it up on a web server?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2010 Jun 13, 2010

The delay while working online is caused by bandwidth like you said at the beginning.To solve this problem create variable assetsToLoad:uint according to my point 1. and assign to it number of the images to load.

Next, return to your initial code (undo the last changes), and we will make a few changes in ThumbItem.as:

public function ThumbItem(num:Number,  cov:String)

{

this.num = num;

this.cover = cov;

//trace(this.cover +  "cover");

this.buttonMode = true;

this.mouseChildren  = false;

loader = new Loader();

this.loader.load(new URLRequest(cov));

// this.thumb.addChild(this.loader);  // we will add the loader to the display list later

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,  imageLoadedComplete);

this.x = num *  65;

this.addEventListener(MouseEvent.ROLL_OVER,  over);

this.addEventListener(MouseEvent.ROLL_OUT,  out);

}

private function  imageLoadedComplete(e:Event):void

{

   var _root:Object = this.root;

     _root.assetsToLoad--;

     if  (_root.assetsToLoad == 0)

     {

           _root.addImagesToClip();

     }

}

// and new public function

public function showYourself():void

{

   this.loader.alpha = 0;  // the image won't be visible at the beginning          

   this.thumb.addChild(this.loader);

   Tweener.addTween(this.loader , {  alpha:1, time:1, transition:"easeOutSine" } );

}

// end of changes in ThumbItem.as

Now in main application code:

// add an array to hold references to thumbs and modify the loop you use to create thumbs:

var aThumbs:Array =  new Array();

for (var i:int = 0; i < picsList.length();  i++)

{

var  thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

aThumbs.push(thumbItem);

}


// create function invoked after all thumbimages finished loading:

public function addImagesToClip():void

{

     for (var i:int = 0; i < picsList.length();  i++)

     {

          this.footerThumbs.scroller.container.addChild(aThumbs);

          aThumbs.showYourself();

     }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

I greatly appreciate your help with this!

I've added the code you've indicated, but run into another 'Error #2006: The supplied index is out of bounds.' So I'm sure I've put something in the wrong place.

This error occurs when the 'showsubcat' function is called.

With your indulgence I'm pasting the entire code for each file here. If it would be helpful I can also provide access to the swf or fla. Thank you again for your help.

GalleryClass.as:

package com.fladev.template.Gallery

{

import flash.display.Loader;

import flash.display.MovieClip;

import flash.display.Sprite;

import flash.events.Event;

import flash.events.MouseEvent;

import flash.net.URLLoader;

import flash.net.URLRequest;

import com.fladev.template.Gallery.ThumbsCategories;

import flash.utils.setTimeout;

import caurina.transitions.Tweener;

import flash.events.Event;

import flash.display.StageAlign;

import flash.display.StageScaleMode;

import flash.events.ProgressEvent;

import caurina.transitions.properties.ColorShortcuts;

public class GalleryClass extends MovieClip

{

private var loader:Loader;

private var urlRequest:URLRequest;

private var urlLoader:URLLoader;

private var xml:XML;

private var numGallery:Number = 1;

private var numOfColumns:int = 6;

private var spacer:int = 0;

private var xmlPath:String = "xml/gallery.xml";

private var stageW:Number = 910 / 2;

private var stageH:Number= 475 / 2;

private var speed:Number = 0;

private var gallerySelected:Number;

private var galleryLength:Number;

private var imageSelected:Number = -1;

private var imageLength:Number;

private var d:XMLList;

private var e:XMLList;

private var thumbBarInitialized:Boolean = false;

private var cX:Number;

private var cY:Number;

private var currentBut:Object;

private var isPlaying:Boolean = false;

private var gallery:Number;

private var subcategory:String;

private var picsList:XMLList;

private var noSubcat:Boolean = false;

private var categories:Array;

private var subcat:Array;

private var subcatNum:Number = 0;

// My added code

public var assetsToLoad:uint;

// End my added code

public function GalleryClass() {

ColorShortcuts.init();

this.addEventListener("showCategories", backCategories);

this.addEventListener("overThumb", overThumb);

this.addEventListener("outThumb", outThumb);

if (stage){

onAddedToStage();

} else {

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

}

}

private function onAddedToStage(e:Event = null):void {

removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

stage.align = StageAlign.TOP_LEFT;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.addEventListener(Event.RESIZE, resizeNormal);

this.addEventListener(Event.REMOVED_FROM_STAGE, destroyGarbage);

resizeNormal();

loadXml();

this.addEventListener(MouseEvent.CLICK, click);

this.categories = new Array();

this.subcat = new Array();

subCategories.visible = false;

bigPicture.visible = false;

prev_btn.visible = false;

next_btn.visible = false;

prev_btn.gotoAndStop(2);

}

//XML/////////////////////////////////////

public function loadXml(e:Event=null) {

urlLoader = new URLLoader();

urlLoader.load(new URLRequest(xmlPath));

urlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

}

public function xmlLoaded(e:Event):void {

Tweener.addTween(this, { alpha:1, transition:"easeOutSine", time:0.8});

xml = new XML(e.target.data);

d  = this.xml.gallery;

galleryLength = d.length();

for (var i:int = 0; i < d.length(); i++) {

var cat:ThumbsCategories = new ThumbsCategories(i, xml.gallery.@title, xml.gallery.@cover, xml.@colorTitleThumb, xml.@thumbColorOver, xml.@thumbColorOut, xml.gallery.@subcategories, xml.gallery.@project);

cat.name = "value" + i;

this.categories.push(cat);

cat.x =  i * 300;

cat.y =  0;

cat.addEventListener(MouseEvent.ROLL_OVER, over);

cat.addEventListener(MouseEvent.ROLL_OUT, out);

this.module.container.addChild(cat);

cat.alpha = 0;

setTimeout(moduleMove, 150 * (i + 1), cat, i);

}

}

private function showSubcat(num:Number):void {

//trace("show subcat");

picsList = this.xml.gallery[gallerySelected].subcategory[num].picture;

imageLength = picsList.length();

// My added code

assetsToLoad = picsList.length();

// End my added code

subcatNum = num;

thumbBarInitialized = true;

Tweener.addTween(footerThumbs, { time:0.5, y:Math.floor(stage.stageHeight - 82 -10), transition:"easeInOutQuint" } );

Tweener.addTween(subCategories, { time:0.5, alpha:0, transition:"easeInOutQuint", onComplete:function ceva() {

subCategories.visible = false;

}} );

footerThumbs.scroller.reset();

bigPicture.visible = true;

bigPicture.alpha = 0;

Tweener.addTween(bigPicture, { time:1, alpha:1, transition:"easeOutSine", onComplete:position } );

// My added code

// add an array to hold references to thumbs and modify the loop you use to create thumbs:

var aThumbs:Array =  new Array();

for (var i:int = 0; i < picsList.length();  i++)

{

var  thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

aThumbs.push(thumbItem);

}

// create function invoked after all thumbimages finished loading:

function addImagesToClip():void

{

for (var i:int = 0; i < picsList.length();  i++)

{

  this.footerThumbs.scroller.container.addChild(aThumbs);

  aThumbs.showYourself();

}

}

// End my added code

footerThumbs.scroller.init();

controlMenu(this.footerThumbs.scroller.container.getChildAt(0) as MovieClip);

prev_btn.visible = true;

next_btn.visible = true;

resizeNormal();

}

private function showPictures(num:Number):void {

//trace("show pictures");

picsList = this.xml.gallery[num].picture;

imageLength = picsList.length();

// My added code

assetsToLoad = picsList.length();

// End my added code

thumbBarInitialized = true;

footerThumbs.scroller.reset();

this.bigPicture.visible = true;

this.bigPicture.alpha = 0;

Tweener.addTween(footerThumbs, { time:0.5, y:Math.floor(stage.stageHeight - 82 -10), transition:"easeInOutQuint" } );

Tweener.addTween(this.bigPicture, { time:1, alpha:1, transition:"easeOutSine", onComplete:position } );

Tweener.addTween(module, { time:0.5, alpha:0, transition:"easeInOutQuint", onComplete:function ceva() {

module.visible = false;

}} );

// My added code

// add an array to hold references to thumbs and modify the loop you use to create thumbs:

var aThumbs:Array =  new Array();

for (var i:int = 0; i < picsList.length();  i++)

{

var  thumbItem:MovieClip = new ThumbItem(i, picsList.@thumb);

aThumbs.push(thumbItem);

}

// create function invoked after all thumbimages finished loading:

function addImagesToClip():void

{

for (var i:int = 0; i < picsList.length();  i++)

{

  this.footerThumbs.scroller.container.addChild(aThumbs);

  aThumbs.showYourself();

}

}

// End my added code

footerThumbs.scroller.init();

controlMenu(this.footerThumbs.scroller.container.getChildAt(0) as MovieClip);

prev_btn.visible = true;

next_btn.visible = true;

resizeNormal();

}

private function loadImage(intSlide:int):void {

imageSelected = intSlide;

//trace("image num " + imageSelected, " galeria selectata " + gallerySelected);

if (noSubcat) {

//trace("load with no subcat", xml.gallery[gallerySelected].picture[intSlide].@img);

bigPicture.loadImg(xml.gallery[gallerySelected].picture[intSlide].@img);

bigPicture.descriptionField.txt.text = xml.gallery[gallerySelected].picture[intSlide].@description;

} else {

//trace("load with subcat", xml.gallery[gallerySelected].subcategory[subcatNum].picture[intSlide].@img);

bigPicture.loadImg(xml.gallery[gallerySelected].subcategory[subcatNum].picture[intSlide].@img);

bigPicture.descriptionField.txt.text = xml.gallery[gallerySelected].subcategory[subcatNum].picture[intSlide].@description;

}

}

private function click(e:MouseEvent):void {

if (e.target is ThumbItem) {

loadImage(e.target.num);

controlMenu(e.target as MovieClip);

}

if (e.target is ThumbsCategories) {

//trace("category " + e.target.title + " was pressed");

switch (e.target.subcategories) {

case "yes":

noSubcat = false;

showSubCategories(e.target.num);

gallerySelected = e.target.num;

Tweener.addTween(module, { alpha:0, time:0.5, transition:"easeOutSine", onComplete:function ceva() {

module.visible = false;

}});

subCategories.init();

break;

case "no":

noSubcat = true;

gallerySelected = e.target.num;

Tweener.addTween(module, { alpha:0, time:0.5, transition:"easeOutSine", onComplete:function ceva() {

module.visible = false;

}});

//trace("no subcategories in " + e.target.title);

showPictures(e.target.num);

break;

}

}

if (e.target is ThumbsSubcategories) {

showSubcat(e.target.num);

}

if (e.target.name == "next_btn") {

nextImage();

}

if (e.target.name == "prev_btn") {

previousImage();

}

if (e.target.name == "btn_backSubcategories") {

if (noSubcat) {

backCategories()

} else {

backSubcategories();

}

}

}

private function showSubCategories(num:Number) {

//trace("show showSubCategories");

var l:Number = subCategories.container.numChildren;

while (l--) {

this.subCategories.container.removeChildAt(l);

}

this.d = this.xml.gallery[num].subcategory;

this.subCategories.container.y = 33;

this.subCategories.totalPages = 1;

this.subCategories.currentPage = 1;

for (var i:int = 0; i < this.d.length(); i++) {

var item:ThumbsSubcategories = new ThumbsSubcategories(i, d.@title, d.@cover);

this.subcat.push(item);

item.name = "value" + i;

item.x =  (i % numOfColumns) * (100);

item.y =  Math.floor(i / numOfColumns) * (130);

this.subCategories.container.addChild(item);

item.alpha = 0;

setTimeout(moduleMove, 150*(i+1), item, i);

}

}

public function moduleMove(mc:MovieClip, i:Number) {

Tweener.addTween(mc, { time:1, alpha:1, transition:"easeOutSine" } );

}

private function over(e:Event):void {

for (var i:int = 0; i < categories.length; i++) {

Tweener.addTween(this.categories, { time:0.4, transition:"easeOutSine", alpha:0.3 } );

}

Tweener.addTween(e.currentTarget, { time:0.4, transition:"easeOutSine", alpha:1 } );

e.target.gotoAndPlay(2);

e.target.info_mc.gallery_txt.text = e.target.title;

e.target.info_mc.project_txt.text = e.target.project;

var numSubcat:Number = this.xml.gallery[e.target.num].subcategory.length();

if (numSubcat != 0 ) {

e.target.info_mc.num_txt.text = this.xml.gallery[e.target.num].subcategory.length() + " SUBCATEGORIES";

} else {

e.target.info_mc.num_txt.text = this.xml.gallery[e.target.num].picture.length() + " PHOTOS";

}

}

private function out(e:Event):void {

for (var i:int = 0; i < categories.length; i++) {

Tweener.addTween(this.categories, { time:0.4, transition:"easeOutSine", alpha:1 } );

}

e.target.gotoAndPlay(11);

}

public function overThumb(e:Event) {

for (var i:int = 0; i < this.subcat.length; i++) {

Tweener.addTween(this.subcat, { time:0.4, transition:"easeOutSine", alpha:0.3 } );

}

Tweener.addTween(e.target, { time:0.4, transition:"easeOutSine", alpha:1 } );

}

public function outThumb(e:Event) {

for (var i:int = 0; i < this.subcat.length; i++) {

Tweener.addTween(this.subcat, { time:0.4, transition:"easeOutSine", alpha:1 } );

}

}

private function nextImage(e:Event = null):void {

if(imageSelected + 1 < imageLength) {

loadImage(imageSelected + 1);

controlMenu(this.footerThumbs.scroller.container.getChildAt(imageSelected) as MovieClip);

} else {

loadImage(0);

controlMenu(this.footerThumbs.scroller.container.getChildAt(0) as MovieClip);

}

}

private function previousImage(e:Event = null):void {

if(imageSelected - 1 >= 0) {

loadImage(imageSelected - 1);

controlMenu(this.footerThumbs.scroller.container.getChildAt(imageSelected) as MovieClip);

} else {

loadImage(imageLength - 1);

controlMenu(this.footerThumbs.scroller.container.getChildAt(imageLength-1) as MovieClip);

}

}

private function backCategories(e:Event=null):void

{

//trace("back categories");

bigPicture.visible = false;

bigPicture.init();

thumbBarInitialized = false;

prev_btn.visible = false;

next_btn.visible = false;

module.visible = true;

module.alpha = 0;

Tweener.addTween(footerThumbs, { time:0.5, y:Math.floor(stage.stageHeight +1), transition:"easeInOutQuint" } );

Tweener.addTween(module, { alpha:1, time:0.5, transition:"easeOutSine" } );

}

private function backSubcategories():void

{

//trace("back subcategories");

bigPicture.visible = false;

bigPicture.init();

thumbBarInitialized = false;

subCategories.visible = true;

subCategories.alpha = 0;

prev_btn.visible = false;

next_btn.visible = false;

Tweener.addTween(footerThumbs, { time:0.5, y:Math.floor(stage.stageHeight +1), transition:"easeInOutQuint" } );

Tweener.addTween(subCategories, { alpha:1, time:0.5, transition:"easeOutSine" } );

}

private function controlMenu(butTarget:MovieClip) {

if (currentBut != null) {

currentBut.deselected();

}

butTarget.selected();

currentBut = butTarget;

}

private function destroyGarbage(e:Event):void {

stage.removeEventListener(Event.RESIZE, resizeNormal);

this.removeEventListener(Event.REMOVED_FROM_STAGE, destroyGarbage);

this.removeEventListener("showCategories", backCategories);

}

private function position() {

var posX:Number = stage.stageWidth*0.5;

var posY:Number = (stage.stageHeight - 82)*0.5;

Tweener.addTween(this.bigPicture, { x:posX, y:posY, transition:"easeOutSine", time:0.5} );

setTimeout(loadImage, 500, 0);

}

private function resizeNormal(e:Event = null) {

cX = Math.floor((stage.stageWidth / 2) - (900 * 0.5));

cY =  Math.max(Math.floor(((this.stage.stageHeight - 82 ) / 2) - 224), 85);

module.x = cX;

module.y = cY;

footerThumbs.x = 0;

footerThumbs.bg.width = stage.stageWidth;

subCategories.x = Math.floor((stage.stageWidth *0.5) - (634 * 0.5));

subCategories.y = Math.max(Math.floor(((this.stage.stageHeight - 82 ) / 2) - 213), 85);

if(thumbBarInitialized) {

footerThumbs.y = Math.floor(stage.stageHeight - 82 - 10);//82 bar height

} else {

footerThumbs.y = stage.stageHeight;

}

prev_btn.y = (stage.stageHeight - 82)*0.5;

next_btn.y = prev_btn.y;

prev_btn.x = 30;

next_btn.x = stage.stageWidth - 30 - 39;

bigPicture.x = stage.stageWidth * 0.5;

bigPicture.y = (stage.stageHeight - 82)*0.5;

if (footerThumbs.scroller.container.width < 527) {

footerThumbs.scroller.x = stage.stageWidth * 0.5 - footerThumbs.scroller.container.width * 0.5;

} else {

footerThumbs.scroller.x = Math.floor((stage.stageWidth * 0.5) - (527 * 0.5));

}

}

}

}

ThumbItem.as:

package com.fladev.template.Gallery

{

import flash.display.Loader;

import flash.display.MovieClip;

import flash.net.URLRequest;

import flash.text.TextField;

import flash.events.MouseEvent;

import flash.text.TextFieldAutoSize;

import caurina.transitions.Tweener;

import flash.events.Event;

import flash.events.ProgressEvent;

import caurina.transitions.Tweener;

public class ThumbItem extends MovieClip

{

public var num:Number;

public var cover:String;

public var title:String;

public var titleColor:String;

public var colorOver:String;

public var colorOut:String;

private var loader:Loader;

// My added code

public function ThumbItem(num:Number,  cov:String)

{

this.num = num;

this.cover = cov;

//trace(this.cover +  "cover");

this.buttonMode = true;

this.mouseChildren  = false;

loader = new Loader();

this.loader.load(new URLRequest(cov));

// this.thumb.addChild(this.loader);  // we will add the loader to the display list later

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadedComplete);

this.x = num *  65;

this.addEventListener(MouseEvent.ROLL_OVER,  over);

this.addEventListener(MouseEvent.ROLL_OUT,  out);

}

private function imageLoadedComplete(e:Event):void

{

   var _root:Object = this.root;

_root.assetsToLoad--;

if  (_root.assetsToLoad == 0)

{

   _root.addImagesToClip();

}

}

// and new public function

public function showYourself():void

{

   this.loader.alpha = 0;  // the image won't be visible at the beginning         

   this.thumb.addChild(this.loader);

   Tweener.addTween(this.loader , {  alpha:1, time:1, transition:"easeOutSine" } );

}

// End my added code

private function over(e:MouseEvent):void {

e.target.border.gotoAndPlay("over");

}

private function out(e:MouseEvent):void {

e.target.border.gotoAndPlay("out");

}

public function selected() {

this.enabled = false;

this.mouseEnabled = false;

this.border.gotoAndStop(14);

this.removeEventListener(MouseEvent.ROLL_OVER, over);

this.removeEventListener(MouseEvent.ROLL_OUT, out);

}

public function deselected() {

this.enabled = true;

this.mouseEnabled = true;

this.border.gotoAndStop(1);

this.addEventListener(MouseEvent.ROLL_OVER, over);

this.addEventListener(MouseEvent.ROLL_OUT, out);

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2010 Jun 13, 2010

I've added the code you've indicated, but run into another 'Error #2006:
The supplied index is out of bounds.'

First, when you post an error, you should provide entire error text - there is a line number in the error that indicates offensive code.

Second, this error indicates that attempt to refer to an object that doesn't exist in display list index. For example if you write:

container.addChild(mc);

container.addChild(mc1);

and then try to read:

trace(container.getChildAt(2)) or trace(container.getChildAt(100)) - it will throw this error because there is no child in index 2 (or 100) - only indexes 0 and 1 have children.

The same error will be thrown if a DisplayObjectContainer doesn't have any children.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

You're right, I should have included the entire error, and forgot to do so after pasting the code. The error is:

RangeError: Error #2006: The supplied index is out of bounds.

at flash.display::DisplayObjectContainer/getChildAt()

at com.fladev.template.Gallery::GalleryClass/showSubcat()

at com.fladev.template.Gallery::GalleryClass/click()

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.fladev.template.Gallery::ThumbItem/imageLoadedComplete()

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.fladev.template.Gallery::ThumbItem/imageLoadedComplete()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2010 Jun 13, 2010

As you can deduce from the error, this is the line in showSubcat() that is responsible for this particular error:

controlMenu(this.footerThumbs.scroller.container.getChildAt(0) as MovieClip); - there is no child in index 0.

But, because you have several points here getChildAt is used, this erro may come pop up again. You need to make sure that you have children at particular index before you try to get them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

By adding some traces I can see that 'addImagesToClip()' is never getting called.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

And neither is the 'imageLoadedComplete()' function. Unfortunately, I'm not able to figure out why...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2010 Jun 13, 2010

In ThumbItem.as move line

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,   imageLoadedComplete);

before the line:

this.loader.load(new URLRequest(cov));

It should be fine than. This event listener should be added before loading starts I didn't notice it earlier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

Thank you; I just tried that but get the same results. The same error message, and the trace statements I added to the two functions mentioned previously don't appear.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2010 Jun 13, 2010

Here are two of the traces I added:

private function imageLoadedComplete(e:Event):void

{

trace ("imageLoadedComplete fired");

   var _root:Object = this.root;

_root.assetsToLoad--;

if  (_root.assetsToLoad == 0)

{

   _root.addImagesToClip();

   trace ("_root bit ran");

}

}

imageLoadedComplete fired does display; _root bit ran does not display.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 14, 2010 Jun 14, 2010

Thank you; I just tried that but get the same results. The same error message, and the trace statements I added to the two functions mentioned previously don't appear.

Does trace("show subcat") appear? Do those two traces appear while testing locally?

I have gone through your code and found some mestakes. At first - does GalleryClass.as is a document class for your fla? If yes, its OK. Otherwise please describe the class structure so we could determine the root.

A few things to correct in GalleryClass.as:

aThumbs should be class level variable and public, just like assetsToLoad, not a local variable in showSubcat function. Also function addImagesToClip shouldn't be nested in showSubcat function. addImagesToClip should be a public function.

Assuming that GalleryClass is the document class (root), in imageLoadedComplete function you can chage typing of _root var. Add also a try catch statement to determine any errors.

private function imageLoadedComplete(e:Event):void

{

     trace ("imageLoadedComplete fired");

     try{

       var _root:GalleryClass = this.root as GalleryClas;

     _root.assetsToLoad--;

     if  (_root.assetsToLoad == 0)

     {

        _root.addImagesToClip();

        trace ("_root  bit ran");

     }

     }catch(e:Error){

           trace("imageLoadedComplete error: " + e.message.toString() );

     }

}

If it still does not help, put the FLA, SWF and source files on some FTP or something so I could look and test it myself.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 14, 2010 Jun 14, 2010

At this point, I have only tested locally since adding your code. No, the 'trace subcat' does not appear.

I've tried what you've suggested here, but with no success yet. I've zipped the files and am putting them up on an ftp link that I will pm to you.

Thank you again, I very much appreciate your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2010 Jun 18, 2010

If there is anyone else reading this who may be able to assist I'd greatly appreciate it; thanks in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 20, 2010 Jun 20, 2010
LATEST

Having added the debugger version of Flash Player to Firefox, I can now verify the error I'm getting is:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

This occurs for some of the thumbnail images in my folder, but not all of them.

The paths are correct.

Are there any other reasons I would get this error? Would a timeout cause this error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2010 Jun 13, 2010

I haven't looked into your code's details so I don't know what it means.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines