Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-18-2012, 01:25 PM   #1
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default Stage resize issue

Hi guys and girls,

I have an issue with an image not being the stage width when it is resized.

Im using greensocks LoaderMax to load the image and tile it across the stage which works fine but when I resize the browser the image doesnt resize and I cant figure out what im doning wrong.

Here is the AS3 for importing and tiling the image:

ActionScript Code:
var footer:Sprite = new Sprite(); var footerImageSpt = new Sprite(); // footer var footerImage:ContentDisplay = LoaderMax.getContent("footerImage"); footerImageGrfx:Graphics = footerImageSpt.graphics(); footerImageGrfx.beginBitmapFill(footerImage.rawContent.bitmapData); footerImageGrfx.drawRect(0, 0, stage.stageWidth, footerImage.height); footerImageGrfx.endFill(); footer.addChild(footerImageSpt);
I did try adding a event listener but couldnt get it to work, it resized the image instead of keeping it tiled.

Any help would be appreciated.
Mighty Flash Gordon is offline   Reply With Quote
Old 06-18-2012, 05:29 PM   #2
solisarg
Senior Member
 
solisarg's Avatar
 
Join Date: Mar 2003
Location: Buenos Aires, Argentina
Posts: 495
Default

The first thing is to disable the automatic resize, then add the listener

this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.addEventListener(Event.RESIZE, handleResize);

This code should be in an object thatis in the DisplayList, if not you will get an error

Jorge
solisarg is offline   Reply With Quote
Old 06-18-2012, 05:51 PM   #3
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

I have this code:

Code:
// stage setup 
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.addEventListener(Event.RESIZE, resizeFooter, false, 0, true);
Then a listener:

Code:
private function resizeFooter(e:Event):void
		{
			if((stage.stageWidth) > footerImageSpt.width)
			{
				TweenMax.to (footerImageSpt, 0.5, {width: stage.stageWidth});
			    trace(footerImageSpt.width);
			}
			else
			{
				TweenMax.to (footerImageSpt, 0.5, {width: footerImageGrfx.width});
			}
			
		}
but this only stretches the image.
Mighty Flash Gordon is offline   Reply With Quote
Old 06-18-2012, 05:53 PM   #4
solisarg
Senior Member
 
solisarg's Avatar
 
Join Date: Mar 2003
Location: Buenos Aires, Argentina
Posts: 495
Default

And that's what your code does, it change the width of footerImageSpt ... what do you expect?

Jorge
solisarg is offline   Reply With Quote
Old 06-18-2012, 06:13 PM   #5
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
Default

Use the drawing API and bitmapFill to tile the image from the library.
Do this in the resizeHandler. That way, the image is tiled to fit when the browser is resized; no scaling or distortion.
[afz]snickelfitz is offline   Reply With Quote
Old 06-18-2012, 06:31 PM   #6
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

The drawing API and bitmapFill are using a dynamic image not an image from the library.
Not sure how to do it. I put this code in the resize handler but it didnt do anything:

Code:
private function resizeFooter(e:Event):void
		{
			if((stage.stageWidth) > footerImageSpt.width)
			{
				addChild (footerImageSpt);
			var footerImage:ContentDisplay = LoaderMax.getContent("footerImage");
			var footerImageBar:Graphics = footerImageGrfx.graphics;
			footerImageBar.beginBitmapFill(footerImage.rawContent.bitmapData);
			footerImageBar.drawRect(0, 0, maxWidth, footerImage.height);
			footerImageBar.endFill();
			footerImageSpt.addChild(footerImageGrfx);
			}
		}
Mighty Flash Gordon is offline   Reply With Quote
Old 06-18-2012, 06:54 PM   #7
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
Default

This script loads an image then tiles across the stage on resize.
ActionScript Code:
import flash.display.Stage; import flash.display.Shape; import flash.display.Graphics; import com.greensock.loading.ImageLoader; import com.greensock.events.LoaderEvent; import flash.display.BitmapData; import flash.display.Bitmap; stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; stage.addEventListener(Event.RESIZE, resizeFooter, false, 0, true); var bmd:BitmapData; var f:Sprite = new Sprite(); addChild(f); var imageLoader:ImageLoader = new ImageLoader("squares.png", {onComplete:parseImage}); imageLoader.load(); function parseImage(e:LoaderEvent):void {     var img:Bitmap = e.target.rawContent as Bitmap;     bmd = img.bitmapData;     resizeFooter(); } function resizeFooter(e:Event=null):void {     var sw:Number = stage.stageWidth;     var sh:Number = stage.stageHeight;     var fh:Number = 200;         f.y = sh - fh;     f.x = 0;         var g:Graphics = f.graphics;     g.beginBitmapFill(bmd);     g.drawRect(0,0,sw,fh);     g.endFill(); }
[afz]snickelfitz is offline   Reply With Quote
Old 06-18-2012, 07:30 PM   #8
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

I got it to work with this:

Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeFooter, false, 0, true);

private function resizeFooter(e:Event):void
		{
			addChild (footerImageSpt);
			var footerImage:ContentDisplay = LoaderMax.getContent("footerImage");
			var footerImageBar:Graphics = footerImageGrfx.graphics;
			footerImageBar.beginBitmapFill(footerImage.rawContent.bitmapData);
			footerImageBar.drawRect(0, 0, stage.stageWidth, footerImage.height);
			footerImageBar.endFill();
			footerImageSpt.addChild(footerImageGrfx);			
		}
I have a footer text field on top of the image but when the screen resized it went on top of my footer text field and i cant see why.
Mighty Flash Gordon is offline   Reply With Quote
Old 06-18-2012, 07:35 PM   #9
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
Default

you are adding footerImageSpt on resize.
This moves the footerImageSpt to the top of the displaylist (above everything else)
don't do that.
[afz]snickelfitz is offline   Reply With Quote
Old 06-18-2012, 07:55 PM   #10
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

ok gotcha ya,

Put this and its all working :

Code:
private function resizeFooter(e:Event=null):void
		{
			var footerImage:ContentDisplay = LoaderMax.getContent("footerImage");
			var footerImageBar:Graphics = footerImageGrfx.graphics;
			footerImageBar.beginBitmapFill(footerImage.rawContent.bitmapData);
			footerImageBar.drawRect(0, 0, stage.stageWidth, footerImage.height);
			footerImageBar.endFill();
		}
Big thanx to ya [afz]snickelfitz
Mighty Flash Gordon 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 10:30 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, 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.