Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 05-10-2012, 04:02 PM   #11
l_tilter0405
Registered User
 
Join Date: Apr 2012
Posts: 8
Default

Sorry to be a big pain but i have that at the beginning of my code. The code i have quickly put together from my original code and your help is now:

Code:
progressBar1.visible=false;
progressBar2.visible=false;
UploadprogressBar.visible=false;

UploadprogressBar.mode=ProgressBarMode.MANUAL;
UploadprogressBar.minimum=0;
UploadprogressBar.maximum=100;

var urlRequest:URLRequest = new URLRequest("xxxx.com/file-reference.php");
urlRequest.method = URLRequestMethod.POST;

// Create FileReference.
var imageFile1:FileReference;
var imageFile2:FileReference;

var count:int = 0;
var imageArray:Array = [imageFile1, imageFile2];

// Create Loader to hold image content
var image1_loader:Loader = new Loader();
var image1_content:Sprite = new Sprite();

var image2_loader:Loader = new Loader();
var image2_content:Sprite = new Sprite();

// Get Extension Function.
var imageExtension;

function getExtension($url:String):String {
    var extension:String = $url.substring($url.lastIndexOf(".")+1, $url.length);
    return extension;
}

// Random Number Function to create new filename on server.
function randomNum(low:Number=0, high:Number=1):Number {
	return Math.floor(Math.random() * (1+high-low)) + low;
}
var myNumber:Number= randomNum(1000,9999);
var myString:String= String(myNumber);
var RandomNumbers = myString;
var imageFile1Path = (RandomNumbers);

// Select Button Function.
select1_btn.addEventListener(MouseEvent.CLICK, onselect1_btnClicked);

function onselect1_btnClicked(event:MouseEvent):void {
	imageFile1=new FileReference();
	imageFile1.addEventListener(Event.SELECT, onFileSelected1);
	var imageTypeFilter:FileFilter = new FileFilter("JPG/PNG Files","*.jpeg; *.jpg;*.gif;*.png");
	imageFile1.browse([imageTypeFilter]);
}

// Select Button Function.
select2_btn.addEventListener(MouseEvent.CLICK, onselect2_btnClicked);

function onselect2_btnClicked(event:MouseEvent):void {
	imageFile2=new FileReference();
	imageFile2.addEventListener(Event.SELECT, onFileSelected2);
	var imageTypeFilter:FileFilter = new FileFilter("JPG/PNG Files","*.jpeg; *.jpg;*.gif;*.png");
	imageFile2.browse([imageTypeFilter]);
}

// File Selected Function.
function onFileSelected1(event:Event):void {
	imageFile1.addEventListener(Event.COMPLETE, onFileLoaded1);
	imageFile1.addEventListener(ProgressEvent.PROGRESS, onProgress1);
	var imageFile1Name = imageFile1.name;
	imageFile1.load();

	progressBar1.visible=true;
	progressBar1.mode=ProgressBarMode.MANUAL;
	progressBar1.minimum=0;
	progressBar1.maximum=100;
}

// File Selected Function.
function onFileSelected2(event:Event):void {
	imageFile2.addEventListener(Event.COMPLETE, onFileLoaded2);
	imageFile2.addEventListener(ProgressEvent.PROGRESS, onProgress2);
	var imageFile2Name = imageFile2.name;
	imageFile2.load();

	progressBar2.visible=true;
	progressBar2.mode=ProgressBarMode.MANUAL;
	progressBar2.minimum=0;
	progressBar2.maximum=100;
	
}

// File Progress Function.
function onProgress1(event:ProgressEvent):void {
	var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
	progressBar1.setProgress(percentLoaded, 100);
}

// File Progress Function.
function onProgress2(event:ProgressEvent):void {
	var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
	progressBar2.setProgress(percentLoaded, 100);
}

// File Loaded Function.
function onFileLoaded1(event:Event):void {
	var fileReference1:FileReference=event.target as FileReference;

	var data:ByteArray=fileReference1["data"];
	var movieClipLoader:Loader=new Loader();
	movieClipLoader.loadBytes(data);
	movieClipLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMovieClipLoaderComplete1);

	imageFile1.removeEventListener(Event.COMPLETE, onFileLoaded1);
	imageFile1.removeEventListener(ProgressEvent.PROGRESS, onProgress1);
}

// File Loaded Function.
function onFileLoaded2(event:Event):void {
	var fileReference2:FileReference=event.target as FileReference;

	var data:ByteArray=fileReference2["data"];
	var movieClipLoader:Loader=new Loader();
	movieClipLoader.loadBytes(data);
	movieClipLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMovieClipLoaderComplete2);

	imageFile2.removeEventListener(Event.COMPLETE, onFileLoaded2);
	imageFile2.removeEventListener(ProgressEvent.PROGRESS, onProgress2);
}

// Load Image onto Stage Function.
function onMovieClipLoaderComplete1(event:Event):void {
	var loadedContent:DisplayObject=event.target.content;
	image1_loader =event.target.loader as Loader;
	
	var scaleWidth:Number=345/image1_loader.width;
	image1_loader.scaleX=image1_loader.scaleY=scaleWidth;
	image1_loader.height=200;
	image1_loader.scaleX=image1_loader.scaleY;
	image1_loader.x=0;
	image1_loader.y=0;
	
	image1_content.buttonMode=true;
	image1_content.addChild(image1_loader);
	addChild(image1_content);
}

// Load Image onto Stage Function.
function onMovieClipLoaderComplete2(event:Event):void {
	var loadedContent:DisplayObject=event.target.content;
	image2_loader =event.target.loader as Loader;
	
	var scaleWidth:Number=345/image2_loader.width;
	image2_loader.scaleX=image2_loader.scaleY=scaleWidth;
	image2_loader.height=200;
	image2_loader.scaleX=image2_loader.scaleY;
	image2_loader.x=0;
	image2_loader.y=200;
	
	image2_content.buttonMode=true;
	image2_content.addChild(image2_loader);
	addChild(image2_content);
}

// Upload Button Function.
upload_btn.addEventListener(MouseEvent.CLICK, onupload_btnClicked);

function onupload_btnClicked(event:MouseEvent):void {
	imageArray[count].addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete);
	imageArray[count++].upload(urlRequest);
}

// Upload File Completed Function.
function onUploadComplete(event:Event):void {
	
	upload_status_txt.text='upload '+count+' complete';
	imageArray[count].removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete);
    
	if(count<imageArray.length) {
		imageArray[++count].upload(urlRequest);
	}
    else {
		upload_status_txt.text='All files loaded';
	}
	
}
l_tilter0405 is offline   Reply With Quote
Old 05-10-2012, 04:09 PM   #12
solisarg
Senior Member
 
solisarg's Avatar
 
Join Date: Mar 2003
Location: Buenos Aires, Argentina
Posts: 496
Default

Create imageArray as an empty Array and use push inside the functions that creates the FileReference

ActionScript Code:
function onselect1_btnClicked(event:MouseEvent):void {     imageFile1=new FileReference();         imageArray.push(imageFile1); ....

Don-t enable the upload button if the array is empty

Jorge
solisarg 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 05:05 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.