Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with actionscript file.

    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;
    }
    }
    Attached Files Attached Files

  • #2
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;
    }
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •