1 Replies - 4857 Views - Last Post: 16 April 2009 - 12:56 PM

#1 valetre   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-April 09

Load a high resolution image in as3

Post icon  Posted 16 April 2009 - 12:48 PM

//Hi this is a code for load high res images using the bites info... I want to know how aply this code to load an //image in a low quality and see how the image is comming better

import flash.net.URLRequest;
import flash.utils.getTimer;
//==================================================================================================
// Declaración de variables
//==================================================================================================
var loader:Loader;
var imageStream:URLStream;
var imageData:ByteArray;
addEventListener(Event.ENTER_FRAME, moveImage);
//==================================================================================================
// Función constructora
//==================================================================================================
function init():void {
	imageStream = new URLStream();
	imageStream.addEventListener( ProgressEvent.PROGRESS , imageStreamProgress );
	imageStream.addEventListener( Event.COMPLETE , imageStreamComplete );
	loader = new Loader();
	addChild( loader );
}
function moveImage(e:Event):void{
	loader.x=0;
	loader.y=0;
}
function imageStreamProgress( event:Event ):void {
	if ( imageStream.bytesAvailable == 0 ) {
		return;
	}
	this.processImageData();
}
function imageStreamComplete( event:Event ):void {
	if ( imageStream.connected ) {
		imageStream.close();
	}
}
function processImageData():void {
	if ( imageStream.connected ) {
		imageStream.readBytes( imageData , imageData.length );
	}
	loader.unload();
	loader.loadBytes( imageData );
}
function loadImage( input:String ):void {
	if ( imageStream.connected ) {
		imageStream.close();
	}
	imageStream.load( new URLRequest( input + '?' + getTimer() ) );
	loader.unload();
	imageData = new ByteArray();
}
init();
loadImage("http://fc03.deviantart.com/fs26/f/2008/095/1/5/They_Stole_The_Moon_Version_2_by_vladstudio.jpg");


Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Load a high resolution image in as3

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1639
  • View blog
  • Posts: 8,504
  • Joined: 07-September 06

Re: Load a high resolution image in as3

Posted 16 April 2009 - 12:56 PM

It very well may be working as intended. The only thing is that if you are using this on your personal computer the load will be almost instant as it won't have to make a request to the web. If it is on the web it may be in your system cache so it will load from memory instead of the web. You have to make sure everything is online, and your web cache doesn't contain the image you are loading to see it go through the process.

I will give it a try when I get to a computer with Flash.

Hope that makes sense.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1