Hi all!!!
After reading and testing some tutorials, I red this topic and tried the code but unfortunately it doesn’t work for all the image, i can grab only the borders: I went trough some code, like local.as, ImageObject.as and after an hour (or maybe more now that I’m thinking.. XD ), I cut all the unnecessary(for me) part of physics and animation stuff and I have now a photo app working ^_^
the next step it’s to learn how to read files, and create lists and so one to manage more photos, from various sources(eg. local files or web)
this is the first file, oggetti.as, saved in app/int/demo/oggetti
package app.demo.oggetti{
import flash.events.TUIO;// allows to connect to touchlib/tbeta
import flash.display.Sprite;
import app.core.action.RotatableScalable;
public class oggetti extends RotatableScalable {//RotatableScalable al posto di sprite fa si che tutta la scena diventi RotatableScalable e quindi ha le proprieta classiche
private var num:Number=3; // numero di immagini da mettere - provvisorio
var foto:Immagine; //immagine class (at bottom)
public function oggetti():void {
//--------connect to TUIO-----------------
TUIO.init(this,'localhost',3000,'',true);
trace("oggetti Initialized");
//----------------------------------------
//crea i vari oggetti immagine
for (var i:int = 0; i < num; i++) {
foto = new Immagine("http://www.google.it/logos/earthday09.gif");//"C:/imm.png");
foto.x = Math.random() * stage.stageWidth;
foto.y = Math.random() * stage.stageHeight;
addChild(foto);
}
}
}
}
import app.demo.oggetti.ImageObject;
import flash.display.Sprite; // Immagine class che incapsula un oggetto sprite e lo rende rotatablescalable
import app.core.action.RotatableScalable;
class Immagine extends RotatableScalable {
public function Immagine( path:String) {
//---RotatableScalable options------------
//noScale = true;
//noRotate = true;
//noMove = true;
//----------------------------------------
var photo:ImageObject = new ImageObject(path);
addChild(photo);
}
}//Immagine
this is the second file, the remake of ImageObject.as, in the same directory of the first .as file
package app.demo.oggetti {
import flash.events.*;
import flash.system.LoaderContext;
import flash.net.URLRequest;
import flash.display.*;
public class ImageObject extends Sprite
{
private var clickgrabber:Shape = new Shape();
private var photoBack:Sprite = new Sprite();
private var photoLoader:Loader = null;
//costruttore
public function ImageObject (url:String)
{
photoLoader = new Loader();
photoLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, arrange, false, 0, true);
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
photoBack.graphics.beginFill(0x000000,0.75);
photoBack.graphics.drawRect(0, 0, 1,1);
photoBack.graphics.endFill();
clickgrabber.graphics.beginFill(0xFFFFFF, 1);
clickgrabber.graphics.drawRect(0, 0, 1,1);
clickgrabber.graphics.endFill();
var request:URLRequest = new URLRequest( url );
photoLoader.unload();
photoLoader.load( request , context);
this.addChild( clickgrabber );
this.addChild( photoBack );
}
//funzione che dispone la foto
private function arrange( event:Event = null ):void
{
photoLoader.x = -photoLoader.width/2;
photoLoader.y = -photoLoader.height/2;
clickgrabber.scaleX = photoLoader.width;
clickgrabber.scaleY = photoLoader.height;
clickgrabber.x = -photoLoader.width/2;
clickgrabber.y = -photoLoader.height/2;
photoBack.scaleX = photoLoader.width;
photoBack.scaleY = photoLoader.height;
photoBack.x = -photoLoader.width/2;
photoBack.y = -photoLoader.height/2;
photoBack.alpha = 0.0;
var image:Bitmap = Bitmap(photoLoader.content);
image.smoothing=true;
image.x = -image.width/2;
image.y = -image.height/2;
this.addChildAt(image,1);
this.scaleX = 0.25; this.scaleY = 0.25;
}
}
}
hope it helps!!