uploading images photo gallery with FileReferenceList as3
Posted: Sat Aug 17, 2013 4:43 am
Here is the root as3 on working local or remote without Security.allowDomain(*) etc
zip file with fla swf and php css etc.
uploads/uploader_cs3_php.zip
Image of ROOT timeline layout
imgs/imageUploader.jpg
imageUploader.php
flashToString.php
zip file with fla swf and php css etc.
uploads/uploader_cs3_php.zip
Code: Select all
import fl.data.DataProvider;
import fl.events.ComponentEvent;
import flash.events.Event;
import flash.net.FileReference;
import flash.net.URLRequest;
import fl.controls.ProgressBarMode;
import fl.controls.ProgressBarDirection;
import fl.controls.NumericStepper;
import flash.events.ProgressEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
/*
imageUploader.fla v2.0 by Kristoffe Brodeur. ©2013 All Rights Reserved.
08-16-2013
*/
//*****PATH
//
function changePath(event:Event):void
{
path=event.target.selectedItem.data;
tF_path.text=path;
}
tF_path.text="";
var path:String="";
var pathArr:Array=
[
{label:"localhost testing",data:"127.0.0.1/clearlyfaded/"},
{label:"remote on www",data:"www.clearlyfaded.com/"}
];
cb_path.dataProvider = new DataProvider(pathArr);
cb_path.addEventListener(Event.CHANGE,changePath);
cb_path.selectedIndex=0;
cb_path.dispatchEvent(new Event(Event.CHANGE));
//*****UPLOAD FOLDER
var folder:String="000";
//
if(this.loaderInfo.parameters.f!=undefined)
{
//
for (var vVar:String in this.loaderInfo.parameters)
{
tF_debug.appendText("\n [var] "+vVar+" | "+this.loaderInfo.parameters[vVar]);
}
folder=this.loaderInfo.parameters.f;//or just cycle all parameters values through root[vVar]=...f and or this[vVar]=...f;
}
tF_folder.text=folder;
//*****BROWSE FILES TO UPLOAD
tF_count.text="";
var req:String="";
var imgFile:String="";
var request1:URLRequest;
var files:Array=new Array();
var picImgArr:Array=new Array();
var showImgArr:Array=new Array();
var imgLen:int=0;
var currC:int=-1;
var currR:int=0;
trace("def");
var icW:int=32;
var icH:int=24;
var padX:int=4;
var picPos:int=-1;
var a:int;
var limCol:int=22;//columns of image icons
var list:FileReferenceList=new FileReferenceList();
list.addEventListener(Event.SELECT,select_pics);
var tgtFile:FileReference;
var soFar:int=0;
bar_total.mode=ProgressBarMode.MANUAL;//has to be set of programmatic changes won't show on the progress bar
bar_total.setProgress(0,100);
//
function init_image(e:Event):void
{
currC++;
//
if(currC>=limCol)
{
trace("!!!!");
currC=0;
currR++;
}
var tgt=showImgArr[picPos].imgLoader.content;
stage.addChild(tgt);
//tF_debug.appendText("\n r["+currR+"] c["+currC+"]");
tgt.x=pl_icons.x+(icW*currC)+padX*currC;
tgt.y=pl_icons.y+(icH*currR)+padX*currR;
tgt.width=icW;
tgt.height=icH;
incr_picPos();
}
//
function load_pic():void
{
showImgArr[picPos]=new Object();
showImgArr[picPos].imgLoader=new Loader();
showImgArr[picPos].imgLoader.contentLoaderInfo.addEventListener(Event.INIT,init_image);
imgFile="http://"+path+"uploader/uploads/"+folder+"/"+files[picPos].name.toString();
showImgArr[picPos].imgLoader.load(new URLRequest(imgFile));
}
//
function pic_loaded(e:Event)
{
soFar=((picPos+1)/imgLen)*100;
tF_debug.appendText("\nLoaded. "+soFar);
bar_total.setProgress(soFar,100);
load_pic();
}
//
function ioErrorHandler(errorEv:IOErrorEvent):void
{
tF_debug.appendText("\nError ["+errorEv+"]");
}
//
function upload_picPos():void
{
tF_debug.appendText("\n["+String(picPos)+"]"+files[picPos].name.toString());
scroll1.update();
tgtFile=FileReference(files[picPos]);
tgtFile.addEventListener(Event.COMPLETE,pic_loaded);
tgtFile.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
try
{
FileReference(files[picPos]).upload(request1);
}
catch(error:Error)
{
tF_debug.appendText("\n Unable to upload file."+Error);
}
}
//
function incr_picPos():void
{
picPos++;
//
if(picPos<imgLen)
{
//tF_debug.appendText("\n"+String(picPos));
upload_picPos();
}
else
{
tF_debug.appendText("\n Finished.");
}
}
//
function select_pics(e:Event):void
{
//tF_debug.appendText("\n****select_pics");
req="http://"+path+"uploader/uploader.php?g="+folder;
tF_debug.appendText("\n[req]\n"+req+"\n");
request1=new URLRequest(req);
files=FileReferenceList(e.target).fileList;
imgLen=files.length;
tF_count.text=String(imgLen);
currC=-1;
currR=0;
//
for(a=0;a<imgLen;a++)
{
currC++;
//
if(currC>=limCol)
{
currC=0;
currR++;
}
picImgArr[a]=new ic_pic();//ic_pic is on the stage off the workarea
stage.addChild(picImgArr[a]);
picImgArr[a].x=pl_icons.x+(icW*currC)+padX*currC;
picImgArr[a].y=pl_icons.y+(icH*currR)+padX*currR;
}
//to check by downloading and place the images after uploading
currC=-1;
currR=0;
//tF_debug.appendText("\n currC: "+String(currC));
incr_picPos();
}
//
function file_browse(e:Event)
{
//tF_debug.appendText("\n****file_browse");
var imgType=new FileFilter("photos .jpg only","*.jpg;");
list.browse([imgType]);
}
bt_browse.addEventListener(MouseEvent.CLICK,file_browse);
imgs/imageUploader.jpg
imageUploader.php
Code: Select all
<?php
$to_root="../";
require $to_root."php/flashToString.php";
$varStr="";
$pos=-1;
$st="";
//
foreach($_GET as $varT=>$valT)
{
$pos++;
//
if($pos>0)
{
$st="&";
}
$varStr.=$st.$varT."=$valT";
}
?>
<?php require $to_root."mS/widgets/htmldec.php";?>
<head>
<link type="text/css" rel="stylesheet" href="upl.css" />
</head>
<body>
<div id="wrap">
<?php echo flashToStringVars("imageUploader.swf","1200","600",$varStr);?>
</div>
</body>
</html>
Code: Select all
<?php
/*
flashToString.php v2.0 by Kristoffe Brodeur. ©2013 All Rights Reserved.
05-18-2013 added variables to be sent to flash module if requested
*/
//-----
function flashToStringVars($swf,$swfW,$swfH,$vars)
{
$flashVarStr=str_replace("^","&",$vars);
$str='
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'.$swfW.'" height="'.$swfH.'">
<param name="movie" value="'.$swf.'" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="quality" value="high" />
<param name="FlashVars" value="'.$flashVarStr.'" />
<embed
src="'.$swf.'"
allowScriptAccess="SameDomain"
quality="high"
pluginspage="http://get.adobe.com/flashplayer/"
type="application/x-shockwave-flash"
FlashVars="'.$flashVarStr.'"
width="'.$swfW.'"
height="'.$swfH.'">
</embed>
</object>';
return $str;
}
?>