I’m going to add the code here so that anyone can see. My problems right now are Getting 20 images to pop up in a grid format. Right now I can only get 5 to show. When a new set of images is added they will start under the last set and continue until 20 are displayed. The other problem is now I need the button (searchNow) to be able to display whatever image a person types into the text field. Here is a photo of the application as well. I’ve gotten a lot of the coding done, but having trouble with this part. Thanks.
{
//===================
//ini variables
//===================
import flash.display.Loader;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.sensors.Accelerometer;
import flash.system.Security;
import flash.text.TextField;
import libs.flickrviewer_mc;
Security.allowDomain("*", "api.flickr.com");
import flash.display.Bitmap;
public class FlickrViewer extends libs.flickrviewer_mc
{
//===================
//ini variables
//===================
private var tag:String;
//===================
//ini variables
//===================
private var xpos:Number = 0;
private var ypos:Number = 0;
private var dif:Number = 150;
private var totalRows:int = 10;
private var count:int = 0;
private var i:int = 0;
private var squares_arr:Array = [];
private var x_counter:Number = 0;
//===================
//flickr variables
//===================
private var key:String = "key goes here"; //your flickr api key
private var per_page:int = 5;
private var page:int = 1;
private var xml_url:String = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key="+key+"&tags="+tag+"&per_page="+per_page+"&page="+page;
//===================
//XML
//===================
private var pics:XML = new XML();
private var pics_url:URLRequest = new URLRequest(xml_url);
private var picsLoader:URLLoader = new URLLoader(pics_url);
//===================
//flickr variables
//===================
private var photo_id:String;
private var photo_owner:String;
private var photo_url:String = "http://www.flickr.com/photos/";
public function FlickrViewer()
{
super();
trace("yo");
this.picsLoader.addEventListener(Event.COMPLETE, picsLoaded);
this.back_btn.addEventListener(MouseEvent.CLICK, goBack);
this.searchFlickr_btn.addEventListener(MouseEvent.CLICK, searchNow);
//this.buttonMode = true;
}
private function searchNow(e:Event):void
{
var url:String = photo_url+"/"+photo_owner+"/"+photo_id;
var req:URLRequest = new URLRequest(url);
(req, "_blank");
}
private function loadImage(img_src:String):void
{
var loader:Loader = new Loader();
var img_url:String = img_src;
var request_url:URLRequest = new URLRequest(img_url);
loader.load(request_url);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);
}
private function progressListener(e:ProgressEvent):void
{
var bl:int = e.bytesLoaded;
var bt:int = e.bytesTotal;
var percent:int = Math.ceil((bl*100)/bt);
}
private function completeListener(e:Event):void
{
for (var i:Number = 0; i < count; i++)
{
const HORIZONTAL_SPACING:Number = 90;
const VERTICAL_SPACING:Number = 90;
const ROWS:int = 20;
var img:Bitmap = e.currentTarget.content;
trace(img.width);
img.x=34 + (count%ROWS)*HORIZONTAL_SPACING;
img.y=110 + Math.floor(count/ROWS)*VERTICAL_SPACING;
img.width = img.height = 75;
this.addChild(img);
count++;
}
}
private function picsLoaded(e:Event):void
{
pics = XML(picsLoader.data);
var stat:String = [email protected]();
var totalPages:int = pics.photos.@pages;
var totalPics:int = pics.photos.@total;
trace("bob",pics);
trace("status: "+stat);
trace("Total pages: "+totalPages);
trace("Total pics: "+totalPics);
trace("-=-=-=-=-=-=-=-=-=-=-=");
var allPics:XMLList = pics.photos.*;
//loadImage(allPics[0]);
for each (var photo:XML in allPics)
{
var pic_src:String = "http://farm"+photo.@farm+".static.flickr.com/"+photo.@server+"/"+photo.@id+"_"+photo.@secret+"_m.jpg";
trace("title: "+photo.@title+" owner: "+photo.@owner);
trace("Source: "+pic_src);
trace("-=-=-=-=-=-=-=-=-=-=-=");
trace(pic_src)
var newName:String = "square_"+i;
loadImage(pic_src);
}
}
//===================
//back button event
//===================
private function goBack(e:MouseEvent):void
{
}
}
}