Pages

May 28, 2009

Path Validator

An English translation is available for this post...
הבטחתי, לא?
אז הנה איזה משהו קטנטן (באמת) שהוא חלק מאיזה פרוייקטון שאני עובד עליו. מדובר בואלידאטור שנועד לבדוק "תקינות" של path שמשתמש בכניס. השימושים די ברורים, למעשה כל אפליקציה שדורשת מהמשתמש להכניס Path כחלק מהפעולות שהוא רוצה לבצע.
הואלידאטור הנוכחי בודק אם בכלל יש קלט ואז, אם יש, הוא פשוט בודק אם הנתיב הזה קיים לוקאלית. זה הכל.
יש שם איזה try…catch קטן בכדי לא לפול על wrong arguments exception שיכול לעוף ברגע ש... יש ארגומנטים שלא יכולים להוות נתיב. זה הכל בתכלס. למטה אתם יכולים למצוא את הקוד של הולידאטור ואת השימוש בו. שימו לב שהאיתחול והשימוש בולידאטור נעשה ב-AS, למרות שהוא יכול להיעשות גם בדרך הקונבנציונאלית ב-MXML.
לכל שאלה, טענה וכיו"ב, אתם יודעים איפה למצוא אותי.
תבלו, וחג גבינות שמח!


I promised, didn’t I?
So here is something real tiny that is a part of some project I’m working on. It’s a Validator which checks a file path that the user have entered. The usage is pretty straight forward, any application that requires the user to enter a valid path as part of the operation he wants to perform. This Validator check if there’s an input at all, and there is, it checks that the file path does exists. That’s about it.
There is a little “try… catch” that ensures that the Validator won’t fall on wrong arguments exception that the File class might throw once the arguments for it are… well… wrong.
That’s it really, you can see the code for the Validator and the usage of it below.
Notice that the instatiation and usage of the validator is made in AS code, though it can be done in the more conventional way, in MXML.
For any question or comment, you know where to find me.
Take care.


PathValidator

package com.flashmattic.validator.pathvalidator {
import flash.filesystem.File;

import mx.validators.ValidationResult;
import mx.validators.Validator;

/**
* This validator validates that a path given is a valid path for an existing
* file or folder.
* @author MBz
*/
public class PathValidator extends Validator {
public function PathValidator() {
super();
}

/**
* Checks for illigal arguments for the File constructor and also if the
* path given is valid and points to an existing file or folder.
* This also checks of any input was inserted, if the user decided that
* this field is requiered.
* @param value
* @return Array
*/
override protected function doValidation(value:Object):Array {
// Convert value to a String.
var inputValue:String = value as String;

// Clear results Array.
var results:Array = new Array();

var validationResult:ValidationResult;

// Call base class doValidation().
results = super.doValidation(value);

// Return if there are errors.
if (results.length > 0) {
return results;
}

if (required && (inputValue == null || inputValue == "")) {
validationResult = new ValidationResult(true,
null,
"no string",
"You must enter a path");
results.push(validationResult);
return results;
}

try {
var testFile:File = new File(inputValue);
if (!testFile.exists) {
validationResult = new ValidationResult(true,
null,
"path not valid",
"Invalid Path");
results.push(validationResult);
return results;
}
} catch (e:ArgumentError) {
validationResult = new ValidationResult(true,
null,
"path not valid",
"Invalid Path");
results.push(validationResult);
}
return results;
}
}
}


Usage

filePathValidator = new PathValidator;
filePathValidator.addEventListener(ValidationResultEvent.VALID, onFilePathValid);
filePathValidator.addEventListener(ValidationResultEvent.INVALID, onFilePathInvalid);
filePathValidator.required = true;

filePathValidator.validate(value);

May 22, 2009

OT: עוד הופעה בעיר הקדושה

כמה OT's אפשר הא?
אני יודע... יש כאלו המתמרמרים, אבל מה אני לעשות? יש התפתחויות מעניינות בתחום המוסיקאלי, ולמרות שה-validator חדש שכתבתי מרתק (את השועלים ואותי...) אני מרגיש הרבה יותר טוב בלבשר לכם על ההופעה הבאה שלנו, בהתרעה של "מהיום למחר?".
הלהקה שלי, TYPO, מופיעה בירושלים במוצ"ש הזה (כן, מחר. זה הקטע של מהיום למחר בד"כ). אנחנו מופיעים עם להקה מצוינת שנקראת the CarSitters, המקום נקרא Bass. ההופעה תתחיל ב-22:00.
תגיעו, מבטיח שלא יהיה דיסקו.

May 05, 2009

OT: הופעה נוספת באוזן!

כן, זהו עוד פוסט שלא קשור לפלקס. תתבעו אותי.
אז ככה, ללהקה שלי יש עוד הופעה ב"אוזן בר" במסגרת ערב מרובע של 4 להקות (וחצי, עוד רגע תבינו למה) שהקונספט שלו הוא סולניות עם להקות בועטות מאחוריהן. האירוע יקרה ב 15 לחודש מאי, כלומר החודש למי שזה לא חלחל עבורו, ביום שישי. לכל הספקנים הנה הלו"ז של חודש מאי, תעיפו מבט.
ת'כלס, ערב של רוק/אינדי טוב, להקות שבאמת שווה להכנס ל- MySpace שלהן ולהטות אוזן. עכשיו, החצי ממקודם הוא מופע חימום של רייצ'ל עזוז (כן, השם מעלה עווית על הפה, אבל בכיף) משהו אינטימי-סטייל עם פסנתר בקטנה, לפי מה הבנתי אמור להיות סבבה. וכמובן דיג'וי של יעל קראוס מהפאניק-אנסמבל (הטו, הטו אוזן) לאורך כל הערב, והכל כולל הכל בעבור 40 שקלין מצלצלין וטיבין.
למי שלא זוכר איך ומה, אתם מוזמנים לקפוץ ל- MySpace שלנו. וכמו שאומרים, נשמח לראותכם במיטב מחלצותיכם, אבזמי-אפכם ומיימית וויסקי.
קפצו ל- Facebook ותנו Attend.

לגבי פלקס, אל חשש אנשים. אני יודע שאני אומר את זה הרבה, אבל יש דברים בגו. יש לא מעט דברים חדשים שתוך כדי עבודה צצו, ואני רוצה לשתף אתכם בהם (אללא יודע למה...)
דב איתי, אוקי?
יאללא ביי.