package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.*;
import com.adobe.serialization.json.*;
public class ScreenCategories extends Sprite {
public var myLoader:URLLoader;
public var filePath:String;
public var myReq:URLRequest;
public function ScreenCategories() {
// constructor code
reLoad();
}
// Constructor: Create an array of three categories
public function reLoad()
{
lastButtonEndedY = 35;
/*
In our real app, we would load in the categories from our database (via a JSON)
Hint: Saving the Objects into the array at the index that equals the ID is advised
*/
filePath = "getCategories.php"; //declare path and file name
myReq = new URLRequest(filePath); //create URLRequest to access the file
myLoader = new URLLoader(); //create URLLoader to load the file
//add event listener to run fileLoaded function when loading is complete
myLoader.removeEventListener(Event.COMPLETE, loadComplete);
myLoader.addEventListener(Event.COMPLETE, loadComplete);
//add event listener to listen for any error thrown during loading process
myLoader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
myLoader.load(myReq); //start loading a file with our URLLoader instance
}
//loading complere so print content of a text file to our Text Field
function loadComplete(e:Event):void
{
var jsonstring:String = myLoader.data;
var categories:Array = JSON.decode(jsonstring);
for (var count:int = 0; count < categories.length; count++) {
var aCategory:Object = category[count];
trace(aCategory.categoryname);
trace(aCategory.categoryid);
}
///////////////
// Consider that it would be more responsible to add these to an array and maintain
// which are being added/deleted, then we could create a print function!
///////////////
}
//if any error was thrown, event was also dispatched and now you can print
//the error description to the text field.
public function ioErrorHandler(e:IOErrorEvent):void
{
trace("There was a problem loading "+filePath+": "+e);
}
}
}
// for each "category" in our list (Array)...
for (var count in categories)
{
// Create a button for each of the categories that exist in our Array
var aCategory:BtnCategory = new BtnCategory(categories[count].category);
// Add the BtnCategory to the stage
aCategory.x = 0;
aCategory.y = lastButtonEndedY;
aCategory.name = categories[count].id; // give it a unique name!
addChild(aCategory);
lastButtonEndedY += (aCategory.getHeight() + 1);
}
addEventListener(MouseEvent.CLICK, mouseClicked);
这应该适用于移动应用的动作脚本3,我需要一个类别列表,将我带到产品列表和产品....但我首先在类别列表上工作从JSON读取值,我已经有一个getCategory.php文件,我的json正确返回.....但当我运行swf它说错误....
答案 0 :(得分:0)
对我来说,filePath = "getCategories.php";
似乎是你的问题
当您在本地或在您的开发环境中运行时,它将在SWF所在的同一目录中查找该页面,这可能对您有用。但是当你发布到不再是php页面位置的手机时
因此,您可能会收到IO错误,因为服务器不存在。
[编辑]
那么现在你终于发布了错误,我可以看到你的问题是什么。
type was not found or was not a compile-time constant: Event
声明无法找到Event类
查看您的代码也不会导入它。
你最接近它的是MouseEvent
因此,不要只是导入MouseEvent,而是尝试这个。
import flash.events.*;