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

Problem with passing an array of images to another class

New Here ,
Nov 15, 2013 Nov 15, 2013

Hi,

I try to pass an array of images into a constructor of another class which then displays the images in a loop.

For some reason the stage doesn't display the images and I don't get any error messages.

This is the document class ImageRotateDemo.as :

package

{

         import flash.display.Sprite;

          public class ImageRotateDemo extends Sprite

          {

                    private var images:Array;

                    private var rotate:ImagesRotator;

                    private var tAmount:Number;

                    public function ImageRotateDemo()

                    {

                              this.images = new Array();

                              this.images = ["images/image1.png", "images/image2.png", "images/image3.png"];

                              this.rotate = new ImagesRotator(this.images);

                              rotate.timeAmount = 2;

                    } // end constructor

          } // end ImageRotateDemo class

}

This is the ImagesRotator.as class :

package

{

      

          import flash.display.Loader;

          import flash.display.LoaderInfo;

          import flash.display.MovieClip;

          import flash.display.Sprite;

          import flash.events.Event;

          import flash.events.ProgressEvent;

          import flash.events.TimerEvent;

          import flash.net.URLLoader;

          import flash.net.URLRequest;

          import flash.utils.Timer;

          import fl.transitions.Tween;

          public class ImagesRotator extends Sprite

          {

                    ////////////////////////////////// FIELDS ////////////////////////////////////////////

                    private var myLoader:Loader;

                    private var imgArray:Array;

                    private var timer:Timer;

                    private var myImage:MovieClip;

                    private var currentImg:uint;

                    ////////////////////////////////// PROPERTIES ////////////////////////////////////////

                    private var _timeAmount:Number;

                    ////////////////////////////////// CONSTRUCTOR ///////////////////////////////////////

                    public function ImagesRotator(img:Array)

                    {

                

                              this.currentImg = 0;

                              this.imgArray = new Array();

                              //this.imgArray = ["images/image1.png", "images/image2.png", "images/image3.png"]; // testing as the document class

                              this.imgArray = img;

                              // Display the first image

                              this.myLoader = new Loader();

                              this.myLoader.load(new URLRequest(this.imgArray[this.currentImg]));

                              this.addChild(this.myLoader);

                              this.currentImg++;

                              this._timeAmount = 2;

                              // Initialize timer

                              this.timer = new Timer(this._timeAmount * 1000);

                              this.timer.addEventListener(TimerEvent.TIMER, doNextTween);

                              this.timer.start();

                    } // end constructor

                    ////////////////////////////////// METHODS ///////////////////////////////////////////

                    private function doNextTween(e:TimerEvent):void

                    {

                              if (this.currentImg == this.imgArray.length)

                              {

                                        // Reset the timer

                                        this.currentImg = 0;

                                        this.timer.reset();

                                        this.timer.delay = (0);

                                        this.timer.start();

                              } // end if

                              this.myLoader = new Loader();

                              this.myLoader.load(new URLRequest(this.imgArray[this.currentImg]));

                              this.addChild(this.myLoader);

                              this.currentImg++;

                              this.timer.delay += (this.timeAmount * 1000); // increase the time for each image

                    } // end doNextTween method

                    ////////////////////////////////// GETTERS AND SETTERS ///////////////////////////////

                    public function get timeAmount():Number {return this._timeAmount;}

                    public function set timeAmount(value:Number)

                    {

                              if(value > 0 && value < 11)

                                        this._timeAmount = value;

                              else

                                        this._timeAmount = 2 // default value in case of wrong data

                    } // end set

          } // end ImagesRotator class

}

Like I said I don't get any errors and if I use the ImagesRotator.as as the document class and uncomment this line: //this.imgArray = ["images/image1.png", "images/image2.png", "images/image3.png"];

then everything works fine since I don't pass anything.

I'm sure I miss something about passing an array of data... ???

Thanks in advance.

TOPICS
ActionScript
299
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
New Here ,
Nov 15, 2013 Nov 15, 2013
LATEST

Ok, sorry folks found the problem:

Forgot to add this line in the document class this.addChild(this.rotate);

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