...

View Full Version : Need help with actionscript file.



Ohthatsnasty
06-25-2012, 04:52 AM
Have a project due in a couple of hours and am recieving several errors in my as file can anyone help?
Heres my as file code:
i have also attached a copy of the fxp file.


// ActionScript file
import mx.collections.ArrayCollection;
import valueObjects.*;

private var file:File;
private var path:String;
private var stream:FileStream;

internal var listArray:ArrayCollection=new ArrayCollection();

public function begin():void
{
readDressData();
readShoesData();
compView.lstView.dataProvider=listArray;

}
public function addDressHandler():void
{
var name:String, category:String,dressSize:uint, colour:String;

name=compAccount.txtName.text;
category=compAccount.txtCategory.text;
dressSize=uint(compAccount.txtWidth.text);
colour=compAccount.txtColour.text;

var theDress:Dress=new Dress(name,category,dressSize,colour);
listArray.addItem(theDress);
saveDressData(theDress);
compAccount.txtName.text=null;
compAccount.txtCategory.text=null;
compAccount.txtColour.text=null;
compAccount.txtWidth.text=null;
theDress=null;
}
public function addShoeHandler():void
{
var name:String, category:String,width:String;

name=compAccount.txtName.text;
category=compAccount.txtCategory.text;
width=compAccount.txtWidth.text;

var theShoe:Shoe=new Shoe(name,category);
listArray.addItem(theShoe);
saveShoesData(theShoe);
compAccount.txtName.text=null;
compAccount.txtCategory.text=null;
compAccount.txtWidth.text=null
theShoe=null;
}
public function readDressData():void
{
try
{
path="Files/dress.txt";
file=File.desktopDirectory.resolvePath(path);

stream=new FileStream();
stream.open(file,FileMode.READ);

var fileData:String=stream.readUTFBytes(stream.bytesAvailable);

var lineEndPattern:RegExp = new RegExp(File.lineEnding, "g");
fileData = fileData.replace(lineEndPattern, "\n");
stream.close();
convertToDressObject(fileData);
}
catch(error:Error)
{
compView.lblFile.text=error.toString();
}
}
public function convertToDressObject(fileData:String):void
{
var name:String, category:String,size:uint, colour:String;
var wheresN:uint=0;
var start:uint=0;
var temp:String;
while(fileData.length!=0)
{
wheresN=fileData.indexOf(":",start);
name=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);

wheresN=fileData.indexOf(":",start);
category=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);

wheresN=fileData.indexOf(":",start);
size=int(fileData.slice(start,wheresN));
fileData=fileData.substring(wheresN+1,fileData.length);

wheresN=fileData.indexOf("\n",start);
colour=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);


var theDress:Dress=new Dress(name,category,size,colour);
listArray.addItem(theDress);
theDress=null;
}
}
public function saveDressData(theDress:Dress):void
{
try
{
path="Files/dress.txt";
file=File.desktopDirectory.resolvePath(path);
var str:String="\n"+theDress.toString();
stream=new FileStream();
stream.open(file, FileMode.APPEND);

str = str.replace(/\n/g, File.lineEnding);
stream.writeUTFBytes(str);
stream.close();

}
catch(error:Error)
{
compView.lblFile.text=error.message;
}
}

public function readShoesData():void
{
try
{
path="Files/shoe.txt";
file=File.desktopDirectory.resolvePath(path);

stream=new FileStream();
stream.open(file,FileMode.READ);

var fileData:String=stream.readUTFBytes(stream.bytesAvailable);

var lineEndPattern:RegExp = new RegExp(File.lineEnding, "g");
fileData = fileData.replace(lineEndPattern, "\n");
stream.close();
convertToShoesObject(fileData);
catch(error:Error)
{
compView.lblFile.text=error.toString();
}
}
public function convertToShoesObject(fileData:String):void
{
var name:String, category:String, width:String;
var wheresN:uint=0;
var start:uint=0;
var temp:String;
while(fileData.length!=0)
{
wheresN=fileData.indexOf(":",start);
name=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);

wheresN=fileData.indexOf(":",start);
category=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);

wheresN=fileData.indexOf("\n",start);
width=fileData.slice(start,wheresN);
fileData=fileData.substring(wheresN+1,fileData.length);

var theShoe:Shoe=new Shoe(name,category,width);
listArray.addItem(theShoe);
theShoe=null;
}
}
public function saveShoesData(theShoe:Shoe):void
{
try
{
path="Files/shoe.txt";
file=File.desktopDirectory.resolvePath(path);
var str:String="\n"+theShoe.toString();
stream=new FileStream();
stream.open(file,FileMode.APPEND);
str = str.replace(/\n/g, File.lineEnding);
stream.writeUTFBytes(str);
stream.close();

}
catch(error:Error)
{
compView.lblFile.text=error.message;
}
}

Ohthatsnasty
06-25-2012, 05:15 AM
Fixed those two errors now error with shoe.as
package valueObjects
{
public class Shoe extends Product
{
private var width:String;

public function Shoe(name:String,categoryID:String,width:String)
{
this.name=name;
this.categoryID=categoryID;
this.width=width;
}

override public function toString():String
{
return super.toString()+":" +width;
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum