Hi all,
I have a "Course" class which contains collection of "CourseItems".
Each CourseItem has a folder associated with it(for its files).
I need to add the CourseItem to a Zip file and after zipping it encrypting.
Using FZip and As3crypto I can do the zip and encrypt the zip file.
Whether to do Encryption or not is upto the user .
Currently my code looks similar to (ignore sytax):
Edit: I will try to add some more info + more description
Basically a Course is a folder(user selectable) with subfolders(courseitems).
mapping subfolder structure to the courseitem object(s).
//main code
var encryptCourse:Boolean;
encryptCourse=true; // read from user..checkbox
var course:Course = new Course("path_coursefolder");//from user input
course.createCourseItems();
//read course folder and create "courseitem" for each subfolder
//and save in "courseItems" collection
//after creating pack course - zip and encrypt
course.Pack(encryptCourse);//encryptCourse bool encrypt course or not
class Course
{
var courseItems:Array; //set when creating
public function Pack()
{
for each (var item:CourseItem in courseItems)
{
item.addEventListener("ZIP_COMPLETE",onitemzip);
item.zip();
}
}
private function onitemzip(e:Event)
{
//if user selected to encrypt..do encryption
//now i want to call the encrypt method :(
//item.Encrypt() //cant call this,,how to refer to "item"??
}
}
class CourseItem
{
var files:Array; //set when creating
var _courseZipfile;
public function ZIP()
{
var ziputil = new Ziputil()
ziputil.createZip("some_name",files);
ziputil.addEventListener(Event.Complete,onZipComplete);
}
private function onZipComplete(e:Event)
{
dispatchEvent(new ZipEvent("ZIP_COMPLETE"));
//dispatch and update progess
//COULD CALL ENCRYPT HERE..but want to avoid.
}
public function Encrypt()
{
//encrypt zip file here
//event of encrypt finish
}
}
Basically in above design I want to call "Encrypt" method of CourseItem in Course after Zipping.
Note : i had earlier changed the courseitem class.
I had tried moving pack inside CourseItem then i cud handle encryption after zip.
But by this i strongly couple Zip and encrypt methods.
After zipping -> encrypt is called compulsarily .
i want refactor my code in such a way that both methods
zip and encrypt are independant of each other?
How can i do the same ..
Thanks all