i have created a page 1024 x 850 and im trying to achieve when typing text into the search_txt and pressing the search_btn images should show on the main_mc but i keep getting the error "type was not found or was not a compile-time constant: Search" and "call to a possibly undefined method Search"
i have three files to complied into creating the search on flickr. AS3 code:
import xml.*;
import flickr.*;
import fl.controls.*;
var search_txt:TextInput = search_txt;
var search_btn:Button = search_btn;
var search:Search = new Search() as Button;
var reader:RSSReader = new RSSReader();
var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
default xml namespace = media;
function rssProcessed(event:Event):void
{
var imgLoader:Loader;
var thumbX:Number = 0;
var thumbY:Number = 65;
for(var i:uint = 0; i < reader.episodes.length(); i++)
{
imgLoader = new Loader();
imgLoader.load(new URLRequest(reader.episodes[i].thumbnail.@url));
addChild(imgLoader);
if(i%5 == 0 && i != 0)
{
thumbY += 80;
thumbX = search_txt.x;
}
imgLoader.x = thumbX;
imgLoader.y = thumbY;
thumbX += 80;
if(i >= 14)
{
break;
}
}
trace(reader.episodes[0].thumbnail.@url);
}
function dataReady(event:Event):void
{
reader.addEventListener(Event.COMPLETE, rssProcessed);
reader.processXML(search.feed);
}
function searchFlickr(event:MouseEvent):void
{
search.search(search_txt.text);
search.addEventListener(Event.COMPLETE, dataReady);
}
search_btn.addEventListener(MouseEvent.CLICK, searchFlickr);
Import XML (file inside this folder is called RSSReader.as)
package xml
{
import flash.events.*;
import flash.net.*;
public class RSSReader extends EventDispatcher
{
private var xmlLoader:URLLoader;
public var feed:XML;
public var episodes:XMLList;
public var title:String;
public var description:String;
public function RSSReader()
{
xmlLoader = new URLLoader();
}
public function load(xmlReq:URLRequest):void
{
xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}
private function xmlLoaded(event:Event):void
{
processXML(new XML(xmlLoader.data));
}
public function processXML(xmlData:XML):void
{
feed = xmlData;
episodes = feed..item;
title = feed.channel.title;
description = feed.channel.description;
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
Import flickr (file inside this folder is called Search.as)
package flickr
{
import flash.net.*;
import flash.events.*;
public class Search extends EventDispatcher
{
private var req:URLRequest;
public var info:URLVariables;
private var loader:URLLoader = new URLLoader();
public var feed:XML;
public function Search()
{
}
public function search(searchStr:String):void
{
req = new URLRequest("https://api.flickr.com/services/feeds/photos_public.gne");
info = new URLVariables();
info.format = "rss_200";
info.tags = searchStr;
req.data = info;
loader.load(req);
loader.addEventListener(Event.COMPLETE, dataLoaded);
}
private function dataLoaded(event:Event):void
{
feed = new XML(loader.data);
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
Does anyone know a fix for this?
The Search class extends EventDispatcher, but you initialize it the search object as a Button. Search needs to extend Button if you want to use it as a button.