PDA

View Full Version : Full Browser Background Picture



Gaia
December 7th, 2007, 07:12 PM
I am trying to build an AS3.0 flash site with a full browser background imagethat scales proportionally like in http://www.kanyon.com.tr/ I found some stuff online but nothing on how to do it with AS3.0
Can anyone help me out please?

Felixz
December 7th, 2007, 08:44 PM
stage.addEventListener(Event.RESIZE,_fitImage);
function _fitImage(event:Event) {
content.width=stage.stageWidth;
content.height=stage.stageHeight;
}

Gaia
December 8th, 2007, 12:10 AM
Thank you for the help,but there is a small problem. Your script does in fact proportionally scales the background picture, but if the browser is not at a proportional size it starts showing the stage. I attached a picture to better explain what I mean. I think this could be avoided by setting a min value for with and height and after that the scroller will kick in. I am a designer and I wouldn't know how to do that You think you can give me a hand?

Felixz
December 8th, 2007, 07:25 AM
Check this example. It fits that image proportionally on whole stage, also there is a html with embed

joshchernoff
December 8th, 2007, 09:47 PM
I have updated my full screen image class.
you can find it here
http://gfxcomplex.com/labs/full_screen_image.zip

This class uses bitmap smoothing for upscaling to help address image artifacts.

I have included a FLA and a swf for demoing. There is also a CSS file for the html that addressees the Padding and Margin default problems.

Usage:

import com.gfxcomplex.display.FullScreenImage;
import com.gfxcomplex.display.events.*;

var image:FullScreenImage = new FullScreenImage(new URLRequest("http://gfxcomplex.com/images/Damn_utensils_by_darkmotiondotcom.jpg"));
addChildAt(image, 0);

image.addEventListener(LoadingEvent.PROGRESS, onProgress);
image.addEventListener(LoadedEvent.COMPLETE, onComplete);

function onProgress(e:LoadingEvent):void{
trace(e.imageData.bytesLoaded, e.imageData.bytesTotal);
}

function onComplete(e:LoadedEvent):void{
trace(e.loaded);
}




here is the main class. Note there are two custom events that are needed if you make it from source, They are listed below.

FullScreenImage Class

/*////////////////////////////////////////////////////
//////////////////////////////////////////////////////
////
//// Full Browser background image
////
//// by Josh Chernoff ( GFX Complex )
//// Copy right ~ josh chernoff ~ 2007
//// All rights reseverd
////
////
//// May be redistobuted under The
//// GNU General Public License (GPL) Agreement
////
//////////////////////////////////////////////////////
*/////////////////////////////////////////////////////


/** gfxcomplex.com display package */
package com.gfxcomplex.display{
import com.gfxcomplex.display.events.*;
import caurina.transitions.Tweener;

import flash.display.Sprite;
import flash.system.LoaderContext;

import flash.display.StageAlign;
import flash.display.StageScaleMode;

import flash.display.Bitmap;
import flash.display.Loader;
import flash.events.Event;

import flash.events.ProgressEvent;
import flash.net.URLRequest;



/**
* Loads a ("jpg or png") from a URLRequest.
* This class requires the "caurina.transitions.Tweener" class which can be found at <a href='http://code.google.com/p/tweener/'> http://code.google.com/p/tweener/ </a>
*
* @usage
* <pre>
* var backgoundImage:FullScreenImage = new FullScreenImage(url:URLRequest);
* addChild(backgoundImage);
* </pre>
*
* @version 0.2
* @author Josh Chernoff
* @author http://www.gfxcomplex.com
*/


public class FullScreenImage extends Sprite{

private var _bytesLoaded:Number;
private var _bytesTotal:Number;
private var _imageHolder:Sprite;
private var _bitmap:Bitmap;
private var _loader:Loader;

public function get bytesTotal():Number{
return _bytesTotal;
}
public function get bytesLoaded():Number{
return _bytesLoaded;
}

public function remove(){
stage.removeEventListener(Event.RESIZE, stageResized);
}


public function FullScreenImage(url:URLRequest) {
_imageHolder = new Sprite();
addChild(_imageHolder);
var loaderContext:LoaderContext = new LoaderContext(true);
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.C OMPLETE, completeHandler);
_loader.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS, progressHandler);
_loader.load(url,loaderContext);
}

private function completeHandler(event:Event):void {
var sW:Number = stage.stageWidth;
var sH:Number = stage.stageHeight;



_bitmap = Bitmap(event.target.loader.content);
_bitmap.y -= _bitmap.height;
_bitmap.smoothing = true;

addChild(_imageHolder);

_imageHolder.addChild(_bitmap);
_imageHolder.width = sW;
_imageHolder.scaleY = _imageHolder.scaleX;

if (_imageHolder.height < sH) {
_imageHolder.height = sH;
_imageHolder.scaleX = _imageHolder.scaleY;
}

_imageHolder.y = sH ;
_imageHolder.alpha = 0;

Tweener.addTween(_imageHolder, {alpha:1, time:2, transition:"linear"});

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, stageResized);

dispatchEvent(new LoadedEvent(LoadedEvent.COMPLETE, true));
}



private function progressHandler(event:ProgressEvent):void {
var imageData:Object = new Object();
imageData.bytesLoaded = event.bytesLoaded;
imageData.bytesTotal = event.bytesTotal;
dispatchEvent(new LoadingEvent(LoadingEvent.PROGRESS, imageData));
}

private function stageResized(event:Event):void {
var sH:Number = stage.stageHeight;
_imageHolder.width = stage.stageWidth;
_imageHolder.scaleY = _imageHolder.scaleX;
if (_imageHolder.height < sH) {
_imageHolder.height = sH;
_imageHolder.scaleX = _imageHolder.scaleY;
}
_imageHolder.y = sH;
}
}
}




LoadedEvent Class:

package com.gfxcomplex.display.events{
import flash.events.Event;
public class LoadedEvent extends Event{
public static const COMPLETE:String = "loaded";
public var loaded:Boolean;

public function LoadedEvent ( type:String,
_loaded:Boolean,
bubbles:Boolean = false,
cancelable:Boolean = false) {

super(type, bubbles, cancelable);
loaded = _loaded;

}
public override function clone():Event{
return new LoadedEvent(type, loaded, bubbles, cancelable);
}
public override function toString():String{
return formatToString("LoadedEvent", "type", "loaded", "bubbles", "cancelable");
}
}
}


LoadingEvent Class:

package com.gfxcomplex.display.events{
import flash.events.Event;

public class LoadingEvent extends Event{
public static const PROGRESS:String = "loading";
public var imageData:Object;

public function LoadingEvent ( type:String,
_imageData:Object,
bubbles:Boolean = false,
cancelable:Boolean = false) {

super(type, bubbles, cancelable);
imageData = _imageData;

}
public override function clone():Event{
return new LoadingEvent(type, imageData, bubbles, cancelable);
}
public override function toString():String{
return formatToString("LoadingEvent", "type", "imageData", "bubbles", "cancelable");
}
}
}

-Z-
December 8th, 2007, 10:54 PM
That's a pretty image, very nice compilation, I need to make something like that for publicity of my game :P

joshchernoff
December 8th, 2007, 11:34 PM
That's a pretty image, very nice compilation, I need to make something like that for publicity of my game :P

the image is from kirupa's own darkmotiom. (http://www.darkmotion.com/)

Gaia
December 10th, 2007, 05:31 PM
Thank you this definitly helps a lot, but it is not quite what I wanted.
Check the http://www.kanyon.com.tr/main_en.html (click about us)
if you put the browser in an unproportional size to the picture it adds scroller
bar and the pic is always aligned the top picture to the top.
Again thanks a lot, I hope I'll be able to help you out one day and pay you back.

NCMentis
December 10th, 2007, 10:46 PM
Just joined and was lurking...

this is something I was looking for - thanks!

I ultimately want to be able to do this

www.brook-pifer.com/ - in addition to showing fullscreen within the player, the player itself is resized to fit the available screen real estate... any ideas?

OK - I was well behaved - dont want to be a jerk and ask questions that have been asked a thousand times before...I actually spent two hours with the Flash Help docs... as a result of which I added the following

this.stage.displayState = StageDisplayState.FULL_SCREEN;
in the function that is called by my mouse event listener
it compiles OK, but nothing happens?
I did import the Stage and the StageDisplayState

This is all in the .as documentClass that links to my .fla

- this is AS3.0 in CS3 - wouldnt know AS2.0 if it bit me :)

Frustrated!!!

JChristian
April 1st, 2008, 06:01 PM
methinks boarders are a CSS issue ... try adding this code to your style sheet:


body{
padding:0px;
margin:0px;
}

tioqo
August 31st, 2010, 10:26 AM
This is gonna take some time!

burnandbass
September 1st, 2010, 04:39 PM
http://www.blog.noponies.com/2008/07/actionscript-3-fullscreen-object-resize-class/ - great class