Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-05-2012, 06:00 PM   #11
eldreams
Registered User
 
Join Date: Oct 2011
Posts: 28
Default

Good thing I logged on and checked to see if there were any replies- this is absolutely amazing! Thank you for all your help - this is exactly what I needed.
I managed to set the index to the proper level and everything is working out fine....Now my only problem:

I have 4 images as a test all 96 DPI at a variance of screen resolutions (to test) such as 1920X1080. These images range from 133KB to 900KB.
The first image happens to be the largest - When simulating a download at 56k the streams start showing the first image trying to load...but after 3 seconds it lines up the next image and so on simultaneously. And once one image loads it goes crazy because the smaller images complete loading before the larger....essentially it lines up a queue that I would assume takes memory.

Is there anyway to load the images before hand (maybe add something to my preloader)? Or keep the images in memory? Or something I can do to make this user-friendly to those with slower connections?

Of course my final project wont have an interval of 3 seconds, maybe 10-15 which would allow more time to load - but I'm still faced with the problem.
Any ideas?
eldreams is offline   Reply With Quote
Old 02-05-2012, 09:20 PM   #12
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,400
Default

This script is slightly different than the previous one.
LoaderMax parses an array of filenames and generates loaders and properties for each, based on the filetype.(in this case .jpg, which results in a batch of ImageLoaders) The images are loaded and pushed into an array.
Once this process is complete, the timer is started and the images are added and removed from the array.
This mitigates the problem of bandwidth causing problems with the Timer delay.
ActionScript Code:
import com.greensock.*; import com.greensock.easing.*; import com.greensock.events.*; import com.greensock.loading.*; import com.greensock.loading.display.*; import flash.display.DisplayObject; import flash.text.TextField; import flash.utils.Timer; LoaderMax.activate([ImageLoader]); var addresses:Array = ["img00.jpg",  "img01.jpg",  "img02.jpg",  "img03.jpg",  "img04.jpg"]; var images:Array = new Array(); var pic:Sprite = new Sprite(); addChild(pic); var progressText:TextField = new TextField(); progressText.text = "0"; progressText.autoSize = TextFieldAutoSize.CENTER; progressText.y = stage.stageHeight / 2 - progressText.height/2; addChild(progressText); var picTimer:Timer; var timerRunning:Boolean; var counter:int = 0; var timerDelay:Number = 2000; var tweenDuration:Number = 1; var loader:LoaderMax = LoaderMax.parse(addresses,  {      name:"galleryLoader",      maxConnections:1,      onComplete:allComplete,      onChildProgress:imageProgress,      onChildComplete:imageLoaded},  {      alpha:0,      centerRegistration:true,      x:stage.stageWidth / 2,      y:stage.stageHeight / 2,      width:stage.stageWidth,      height:stage.stageHeight,      scaleMode:"proportionalOutside"}) as LoaderMax; loader.prependURLs("images/", false); loader.load(); function imageProgress(e:LoaderEvent):void {     var percent:int = e.target.progress * 100;     progressText.x = stage.stageWidth / 2 - progressText.width/2;     progressText.text = e.target.url + " " + percent + "%"; } function imageLoaded(e:LoaderEvent):void {     var img:ContentDisplay = e.target.content as ContentDisplay;     progressText.text = "0";     images.push(img); } function allComplete(e:LoaderEvent):void {     removeChild(progressText);     var p:ContentDisplay = images[counter] as ContentDisplay;     pic.addChild(p);     TweenMax.to(p, 1, {alpha:1});     picTimer = new Timer(timerDelay);     picTimer.addEventListener(TimerEvent.TIMER, newPic);     picTimer.start();     timerRunning = true;     counter++;     stage.addEventListener(MouseEvent.CLICK, startStop); } // load new bitmap from the array; increment counter function newPic(e:TimerEvent):void {     var _p:ContentDisplay = pic.getChildAt(0) as ContentDisplay;     TweenMax.to(_p, tweenDuration, {alpha:0, onComplete:pic.removeChild, onCompleteParams:[_p]});     var p:ContentDisplay = images[counter] as ContentDisplay;     trace(p);     pic.addChild(p);     TweenMax.to(p, tweenDuration, {alpha:1});     if (counter < images.length - 1)     {         counter++;     }     else     {         counter = 0;     } } function startStop(e:MouseEvent):void {     if (timerRunning)     {         picTimer.stop();     }     else     {         picTimer.start();     }     // toggle timerRunning;     timerRunning = ! timerRunning;     trace("timerRunning: " + timerRunning); }
[afz]snickelfitz is offline   Reply With Quote
Old 02-05-2012, 10:29 PM   #13
eldreams
Registered User
 
Join Date: Oct 2011
Posts: 28
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
This script is slightly different than the previous one.
LoaderMax parses an array of filenames and generates loaders and properties for each, based on the filetype.(in this case .jpg, which results in a batch of ImageLoaders) The images are loaded and pushed into an array.
Once this process is complete, the timer is started and the images are added and removed from the array.
This mitigates the problem of bandwidth causing problems with the Timer delay.
ActionScript Code:
import com.greensock.*; import com.greensock.easing.*; import com.greensock.events.*; import com.greensock.loading.*; import com.greensock.loading.display.*; import flash.display.DisplayObject; import flash.text.TextField; import flash.utils.Timer; LoaderMax.activate([ImageLoader]); var addresses:Array = ["img00.jpg",  "img01.jpg",  "img02.jpg",  "img03.jpg",  "img04.jpg"]; var images:Array = new Array(); var pic:Sprite = new Sprite(); addChild(pic); var progressText:TextField = new TextField(); progressText.text = "0"; progressText.autoSize = TextFieldAutoSize.CENTER; progressText.y = stage.stageHeight / 2 - progressText.height/2; addChild(progressText); var picTimer:Timer; var timerRunning:Boolean; var counter:int = 0; var timerDelay:Number = 2000; var tweenDuration:Number = 1; var loader:LoaderMax = LoaderMax.parse(addresses,  {      name:"galleryLoader",      maxConnections:1,      onComplete:allComplete,      onChildProgress:imageProgress,      onChildComplete:imageLoaded},  {      alpha:0,      centerRegistration:true,      x:stage.stageWidth / 2,      y:stage.stageHeight / 2,      width:stage.stageWidth,      height:stage.stageHeight,      scaleMode:"proportionalOutside"}) as LoaderMax; loader.prependURLs("images/", false); loader.load(); function imageProgress(e:LoaderEvent):void {     var percent:int = e.target.progress * 100;     progressText.x = stage.stageWidth / 2 - progressText.width/2;     progressText.text = e.target.url + " " + percent + "%"; } function imageLoaded(e:LoaderEvent):void {     var img:ContentDisplay = e.target.content as ContentDisplay;     progressText.text = "0";     images.push(img); } function allComplete(e:LoaderEvent):void {     removeChild(progressText);     var p:ContentDisplay = images[counter] as ContentDisplay;     pic.addChild(p);     TweenMax.to(p, 1, {alpha:1});     picTimer = new Timer(timerDelay);     picTimer.addEventListener(TimerEvent.TIMER, newPic);     picTimer.start();     timerRunning = true;     counter++;     stage.addEventListener(MouseEvent.CLICK, startStop); } // load new bitmap from the array; increment counter function newPic(e:TimerEvent):void {     var _p:ContentDisplay = pic.getChildAt(0) as ContentDisplay;     TweenMax.to(_p, tweenDuration, {alpha:0, onComplete:pic.removeChild, onCompleteParams:[_p]});     var p:ContentDisplay = images[counter] as ContentDisplay;     trace(p);     pic.addChild(p);     TweenMax.to(p, tweenDuration, {alpha:1});     if (counter < images.length - 1)     {         counter++;     }     else     {         counter = 0;     } } function startStop(e:MouseEvent):void {     if (timerRunning)     {         picTimer.stop();     }     else     {         picTimer.start();     }     // toggle timerRunning;     timerRunning = ! timerRunning;     trace("timerRunning: " + timerRunning); }
Thank you snickelfitz! hmm but now when I plug this code in my stage event listener (resize) does not work. Any ideas?
I need to keep the stage re-size/proportional background (pic) piece.
Gracias!
eldreams is offline   Reply With Quote
Old 02-08-2012, 12:10 AM   #14
eldreams
Registered User
 
Join Date: Oct 2011
Posts: 28
Default

Hmm I still haven't figured it out - any ideas?
I'm not too familiar with adding sprites in the fashion.

Code:
var pic:Sprite = new Sprite();
I tried:

Code:
stage.addEventListener(Event.RESIZE, sizeListener);

function sizeListener(e:Event):void {
pic.x=stage.stageWidth / 2;
pic.y=stage.stageHeight / 2;
pic.width=stage.stageWidth;
pic.height=stage.stageHeight;
}

To no avail.

I noticed the proportional scaling occurs here:

Code:
var loader:LoaderMax = LoaderMax.parse(addresses, 
 {
     name:"galleryLoader", 
     maxConnections:1,
     onComplete:allComplete,
     onChildProgress:imageProgress, 
     onChildComplete:imageLoaded},
 {
     alpha:0, 
     centerRegistration:true,
     x:stage.stageWidth / 2,
     y:stage.stageHeight / 2,
     width:stage.stageWidth,
     height:stage.stageHeight,
     scaleMode:"proportionalOutside"}) as LoaderMax;
	 
	 loader.prependURLs("images/", false);
loader.load();
How do I keep the image proportion upon scaling/resizing?
Any ideas?

Muchas Gracias!
eldreams is offline   Reply With Quote
Old 02-08-2012, 10:08 PM   #15
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,400
Default

I'll have a look at it later today.
[afz]snickelfitz is offline   Reply With Quote
Old 02-09-2012, 05:57 PM   #16
eldreams
Registered User
 
Join Date: Oct 2011
Posts: 28
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
I'll have a look at it later today.
Awesome - Thank you!
eldreams is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:53 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.