Pages

August 21, 2009

Flashmatticomponents – Open Source Flex/AIR Library by Flashmattic

An English translation is available for this post...

כותרת מפוצצת, הא? כן... אבל יש סיבה.
שלא תגידו שסחבק בא עם כל מיני "אני מכין לכם משהו", אבל יוצא מוסכניק בסוף. בחודש האחרון אני עמל על פרוייקט חדש ופריימוורק מגניב (לדעתי, אבל איך אומרים – "קוף בעיניי אימו, איילה"). אז אם כן, בשעה טובה ומוצלחת, אני פורש את הדברים לפניכם, והרי עיקרם:
זה נכון שכחלק מתהליך עבודה, אתה מוצא עצמך בונה סט של קומפוננטות, ואם יורשה לי, פריימוורקים לשימוש האישי. ככה זה, והרי זה מבורך, אבל אחרי זמן מה הסוציאליסט החבוי שבך מתחיל להרים ראש ולשאול "למה לא לחלוק... בנאדם?".
אז הנה אני מוצא עצמי בונה פרוייקט קוד-פתוח בחסות google-code, בשם Flashmatticomponents (שימו לב לקופירייטינג המושחז והמרטיט). הפרוייקט הזה, כמו כאלו שקדמו לו, יכיל קומפוננטות ופריימוורקים וכל דחפין יתי ויאכל. הקוד פתוח, כלומר שראשית, ניתן להוריד את ה SWC ולהשתמש בו כאוות נפשכם בכל פרוייקט העולה על רוחכם, ושנית, ניתן להוריד את ה source בעזרת SVN, לייבא את הפרוייקט לפלקס בילדר הקרוב לביתכם ולהתעמר בו. הרשיון לשימוש הוא Apache License 2.0.
אז לפני שאני אתן לכם את הקישור, אגיד לכם מה יש שם כרגע, ככה שלא תופתעו:
יש שם את ה PathValidator שפרסמתי לא מכבר. למי שלא זוכר, זהו וואלידטור המוודא שנתיב ל file system הוא ואלידי ומצביע אל קובץ או תקייה אמיתיים. זה בקטנה, ככה באפרטיף.
מה שבאמת מגניב הוא פריימוורק חדש שקראתי לו “Wizard”.
Wizard הוא פריימוורק שכל יעודו הוא לתת מענה קל ופשוט לייצירת step-by-step wizards בפלקס. אני לא מאמין שיש מישהו שלא יודע מה זה wizard, אבל לכל אלה שלא התקינו אפליקצייה מימיהם, ועשו next-next-next, אני אסביר שזה המקום שבו אתם בד"כ עושים... next-next-next.
ה- Wizard נותן כמה יכולות מאד מתבקשות, כמו:
1. הגדרת צעדים בתוכו היא קלה ומאד אינטואיטיבית.
2. מנהל את הנוויגציה בין הצעדים השונים בו.
3. מדספטצ' events עבור כל פעולה בו, בין אם עוברים לצעד הבא, או חוזרים אחור, מבטלים או מסיימים את ה- Wizard.
4. קובע את הגודל של עצמו נכון לגודל הצעדים שבתוכו. המפתח לא צריך לדאוג לכל עניין המדידה.
5. אחראי על איסוף המידע בכל צעד והשמה שלו באובייקט Data Model שהוזרק לו מבעוד מועד.
6. יכול להתבטל בכל רגע נתון.
סבבה, לא?
בכל אופן, את "איך משתמשים" ודוגמאות קוד תוכלו לקרא בדפי ה- Wiki של הפרוייקט, וכמובן אם יותרו לכם שאלות, אני פה (או שם), פשוט תפרסמו הערה ואני כבר אטפל בעניין. לא לא, זה מאד חשוב – כל הערה, שאלה משאלה (או גם מילה טובה, אם יש על מה) אני אשמח לשמוע ולפעול בהתאם, בטח ובטח אם גילתם באג סורר, או התנהגות לא צפויה/נכונה, אפשר לדווח על באגים בדף הפרוייקט עצמו.

אז עכשיו, כל שנותר הוא לקפוץ לאתר הפרוייקט, להוריד ולנסות.
תבלו :).



Grand headline, euh? Yeah… but there’s a good reason for that.
Just so that you won’t say that I come up with those promises of “cool stuff”, and later fail to deliver, I will let you know that I’ve been working on a new project and a cool framework for the past month or so, and if you allow me, I will present it now:
It’s true, that as a part of a working process you find yourself building a set of components, and dare I say frameworks that will help you along the road. That’s just the way it is, and a good thing too, but after a while the collaborative persona within you rears its head and starts asking: “why not share… mate?”
So I find myself building an Open Source project under Google-Code with the name of “Flashmatticomponents” (whiteness the marvelous and spin-shivering copywriting). This project, like other Open Source projects contains components and frameworks, so that whoever wishes to use them, will be able to.
The code is open, which means that you can download the SWC and use it freely in you project, and secondly, you can download the source and, import the project into your Flex Builder and mess with it. The Open Source Licensing is Apache License 2.0.
So, before giving you the link to the Google code site, I will tell you what currently can be found there, so that it won’t catch you in surprise:
You will find the PathValidator that I’ve recently published here. To those who don’t remember, it’s a Validator that checks the validity of native paths to the local file system. Pretty handy for any AIR application that uses file access, but this is just the aperitif…
What is really cool is the new framework that I named “Wizard”.
Wizard is a framework that its whole purpose is to make the implementation of wizards in Flex/AIR easy. The Wizard gives some very trivial behaviors:
1. Steps are easily implemented and added to the wizard, allowing the developer to concentrate on more important stuff.
2. It is responsible for the navigation within it, whether the next or previous steps are available and knows when the user has reached the end of the wizard.
3. It dispatches events for each relevant stated of the Wizard, such as: moving forward to the next step or moving backwards to the previous one, canceling it and of course when the Wizard is completed.
4. It is responsible for scaling itself according to its steps measured size. The developer using it should not be bothered with setting width and height to the Wizard or the steps.
5. The Wizard is also responsible for collecting the information the user has entered throughout the steps and package them into a data model object given to it.
6. The wizard can be canceled at any stage.
Sweet, right?
Anyway, you’ll find “how-to”’s at the project Wiki, and of course, if you still have questions, submit a comment and I will happily attend to it. No really – this is very important, if you have any wish, question, found a bug or simply have something nice to say, I will be glad to hear about it.
All there is left now is to jump to the project site, download and try it.
Enjoy :).

August 06, 2009

OT: הופעה של TYPO במעבדה, ירושלים

מה המצב?
לא, לא, שלא תגידו, גם הפעם אני אפתח בהתנצלות כוללת על כך שהעדכונים לא תכופים כשהיו, וכרגיל אקנח בכך שמחכה לכם, קוראים יקרים, פינוק פלקסי שיגניב לכם את האיברים הצנועים ביותר.
בכל מקרה, באתי הלום בכדי לספר לכם ש-TYPO (הלהקה של עבדכם הנאמן, לכל מי שלא מעודכן) תופיע ביום שישי הזה, אוגוסט 7, בשעה 14:00 (כן, זה הקטע) ב"מעבדה" בירושלים. הפעם אנחנו מארחים ראפר מ-UK העונה לשם Lord Thunda ודופקים איתו כמה שירים.
אתם מוזמנים לקרא על האירוע פה: אירועים במעבדה, וכמובן להגיע ולשמוע :).
נתראה שם.

June 28, 2009

Nice flow chart for Component's life cycle

An English translation is available for this post...

מה זה ככה, יום אחרי יום? משהו לא תקין...
פשוט נתקלתי במשהו שאתם וודאי תעריכו כמו שאני הערכתי. איזה flow chart פשוט המתאר את ה-life cycle של ה- UIComponent. תכלס, כמה פעמים נתקלנו בדוקומנטציה הביצתית המתארת את התהליך, הא? אז הא לכם chart מבית היוצר של Dan Orlando.
תבלו.


So... what's going on? a "day-after-day" post? something is wrong...
It's just that I bumped into something that you might appreciate as I did. It's a flow chart that simply describes the life cycle of the UIComponent. To be honest, how many times did we encounter that swampy documentation that describes that process, right? so there you go, the chart out of the hand of Dan Orlando.
Enjoy.

June 27, 2009

Catalyst Motivation as I see it

An English translation is available for this post...

אהלן אהלן,
לפני יומיים, למי שלא ממש מעורה, התנהל כנס פלאשו שהציג את המוצרים החדשים של אדובה עם שימת דגש על Catalyst ו- Flash Builder 4. לפני שאפרוש פה את דעתי המתגבשת, חשוב לציין שלא יצא לי להתעסק עם Catalyst, ובכנס הייתה זו למעשה הפעם הראשונה שראיתי את תהליך העבודה המצופה מתבצע בה.
כמו שכתבתי בעבר מחולליי קוד כדוגמת קטאליסט וחברים מאז ומעולם העבירו צמרמורת קרה בגבי. הכלים הללו בד"כ יוצרים כל כך הרבה ג'אנק של קוד מאחור שלעיתים מזיקים יותר ממועילים. אחרי שאמרתי זאת, אני לא מאמין שהכוח או המוטיבציה מאחורי קטאליסט הוא ביצירת קוד מעיצוב. תסתכלו על Flex Builder עד כה, גם בו היינו יכולים להכנס אל ה- design mode להניח קומפוננטות על הבמה והקוד היה נכתב מאליו מאחור (גם אז, לא תמיד לשביעות רצוננו). זו אינה הנקודה. מה שקאטליסט נותן לנו בעצם הוא את היכולת לפצל את ה- layout וה- skinning מהלוגיקה של הקומפוננטות בצורה קלה. כל הרעיון של Spark די עונה על השאלה שהצגתי בפוסט הזה. הקומפוננטות כבר לא בנויות כמקשה אחת, ויש לנו את ההזדמנות ליצור layouts ו-skins שונים לאותה לוגיקה בדיוק. אם אני טיפה אתיימר, אוכל לומר ש-Spark היא בעצם תולדה של הצורך לתת למעצבים אפשרות קלה לשנות ייצוג קומפוננטות של ה-framework. אני מניח, שכמו כל מי שרצה להרחיב את הקומפוונטת של פלקס, גם הצוות באדובה נתקל בקירות בטון מזויינים ברגע שניסה לשנות את ה- layout של הקומפוננטות וזה הביא אותו למסקנה שהתשתית בנויה לא נכון. מסקנה שכל מי שמפתח בפלקס אפליקציות מעט יותר מתוחכמות מאתרי אינטרנט יכל להצביע עליה לפני שנים, אבל מוטב מאוחר מאף פעם לא. אם כך, מה ש-Catalyst מאפשר לנו הוא ליצור את קבצי ה layout וה-skinning בקלות, ולדעתי לשם כיוונו אדובה.
ה- designer developer workflow שאדובה כל כך מדברים עליו הוא הקונספט העיקרי שקאטליסט משחק בו תפקיד של מתווך. הרעיון, לפי הבנתי, הוא לא לצפות מה- designer לקוד, אלא יותר ל- assets ולקבצי ה-layout/skinning הנדרשים. לבנות פתרון end to end מפוטושופ (למשל) עד ל-swf של האפליקציה. ועל פניו... זה נראה לא רע בכלל :).


Hi there,
Couple of days ago, for those who don’t have their finger on the Flex pulse, Flashoo conducted a meeting to display the new Adobe product, giving the main stage to Flash Catalyst and Flash Builder. Before I will reveal my “still incarnating” opinion, It’s important I’ll mention that I hadn’t got the chance to mess around with Catalyst, and the meeting was the first time I saw the work process in action.
As I wrote before, code generators, the likes of Catalyst and friends have never been my bag (baby).These tools usually create do much junk in the code they generate that sometime they are doing more harm the good. Having said that, I don’t believe that the power or motivation behind Catalyst lies in code generation by design. Look at Flex Builder so far; it too has the ability to enter the design mode, drug some component on to the stage and see the code getting written at the back (and then too, the code wouldn’t always be what we intended it to be). That’s not the point. What Catalyst brings us is the ability to separate the layout and skinning from the logic of the components in an easy manner. The whole idea behind Spark pretty much answers the post I published a while ago. The components are no longer built as one class containing both layout and logic and we have the opportunity to create layouts and skins that are different, that will come on top of the same logic. Some might call it MVC…
If I may be a little pretentious, I can say that Spark came from a desperate need to give the designers the ability to alter components layouts. I assume, that like anyone who tried to extend the framework components, the Flex team also encountered some serious bumpers on the way and that made them come to the conclusion that the framework is not flexible enough – a conclusion that anyone who builds Flex application a bit more complicated than the average web site had reached years ago, but better late than never. Therefore, what Catalysit enables us is to create those layout and skinning files easlity, and I do think that this is what Adobe were aiming for.
The design developer workflow that Adobe so constantly are talking about is the main concept that Catalyst plays the role of the mediator in it. The idea, as I understand it, is not to expect code form the designer but rather expect the assets and layout files she’s generating and using, all this to build an end-to-end solution, from Photoshop (for instance) to the application .swf.
So far… doesn’t look bad at all :).

June 10, 2009

Are Components Views and vice versa?

An English translation is available for this post...

המוטיבציה לכתיבת הפוסט שלפניכם הגיעה משיחה קצרצרה שניהלתי בוקר אחד עם קולגה בעבודה, שהעלתה בי סימני שאלה מטרידים מעט בכל הקשור לארכיטקטורת קומפוננטות פלקס אל מול ארכיטקטורת views או יותר נכון Presentation Model. לצורך הדיון, אני אסביר בקצרה מה ה presentation model אומר; אפלקציית פלקס מורכבת בעיקר מרכיבי view שמייצגים את האיזורים השונים בה. View יכול להיות מסך Login, או טאב מסוים. לכל view שכזה יש את ה"ברזלים" שלו, שהם בעצם הקונטרולים הפלקסיים (containers, lists, buttons) ואת הלוגיקה שעומדת מאחור שכוללת את המצבים השונים של ה view ואת החישובים השונים הקשורים ללהתנהגות המצופה ממנו. הלוגיקה תמצא במה שאנחנו נקרא לו presentation model. וכך, כשאנחנו רוצים לבנות view מסוים, הוא חייב להיות מורכב לפחות מ- Class שמייצג את ה view ו-Class שמייצג את ה presentation model. יש המון יתרונות לשיטת פיתוח זאת מעבר להפרדה הברורה בין הרכיבים, אחד מהם, למשל, הוא טסט-אביליות נוחה.
אני בכוונה לא מרחיב מעבר לכך, בכדי לא לבלבל שלא לצורך.
בתור פלקסאי ותיק, אני מכיר את ה-framework של פלקס (לפחות,כרגע, עד SDK 3.x) ומכיר את מבנה הקומפוננטות הפלקסיות כמו Button, DataGrid וכיו"ב. עכשיו, זה נכון שגם שתי הנ"ל הן לכאורה view ולוגיקה הבאה לשמור על state ועל התנהגות מצופה, רק שב- framework הקומפוננטה Button מיוצגת ע"י Class אחד וכך גם DataGrid ועוד.
צורת הארכיטקטורה הזו, של קומפוננטות הפלקס, נראתה לי נכונה, שכן, לא ראיתי את הצורך לחלק את הקומפוננטה לשניים כאשר אין view שמיוצג ע"י MXML (ובמקרה הזה אני עושה את זה יותר עבור נוחות). הקומפוננטות עדיין היו טסט-אביליות, encapsulated ו-reusable.
אם אני אחזור לפתיחה, השאלה שנשאלתי הייתה מה שונה בין קומפוננטה ל-view, ולצורך ההפשטה – במה שונה מסך Login שנבנה בצורה גנרית לקומפוננטת כפתור גנרית? האם זה נכון לבנות קומפוננטת עם presentation model? האם יש מקום למינוח "קומפוננטה" בפלקס בכלל?
אני, כמו שאני, בוקר זה לא בדיוק פרק הזמן שאתם רוצים לפנות אליי בשאלות מהסוג שדורש חשיבה כלשהי, ישר התרעמתי ואמרתי ש"מה זאת אומרת? View זה view וקומפוננטה זו קומפוננ...”, אבל תוך כדי הרגשתי שמשהו חורק בהכרזה הזו. למה באמת לא לעשות קומפוננטות עם presentation model מאחוריהן? נכון לעכשיו, זה נראה לי יותר ויותר פתרון ארכיטקטוני נכון. זה נכון שיש לנו AS שבונה UI, אז מה? מדוע לא לפרק את הלוגיקה מה- view גם במקרה הזה?
אני עדיין מהרהר בזה ולכן אני מפרסם את הפוסט הזה. מאד הייתי רוצה לשמוע מה אתם חושבים ומה דעתכם.
תודה.

The motivation for writing this post in front of you came from a brief coffee-stand conversation I had the other morning, that raised some troubling thoughts and questions to my mind in all that is regarding the view architecture or to be more precise, the “presentation model” architecture.
For the sake of conversation, I’ll explain in short what the presentation model says; Flex application is mostly made of views that represent different areas in it. A view can be a login screen of a tab for that matter. To each view you have the “iron skeleton” which is the flex control (containers, Buttons, Lists) and the logic that stands behind it, which includes the different states of the view and other calculations that makes it work as expected. The logic will reside on, what we call, the Presentation Model class, and so, when we wish to build a certain view it has to made out of (at least) 2 classes. There are many advantages to this kind of architecture, say, easy testability.
I’m not going deeper to this architecture to keep you focused on the main problem.
As a veteran Flex developer I can pretty much say that I know the Flex framework (at least, until SDK 3.x) and know the component architecture like DataGrid and Button, etc. Now, it’s true that the ones I’ve mentioned are, apparently, views and logic that maintain the view states and its behavior, only that in the Flex Framework these components are represented as a single class.
This architecture of the Flex framework seemed right to me, that is, I didn’t see any need to divide the component into two where there is no view that is represented with MXML (in that case I do it for convenience). The components will still be testable, en capsulated and reusable.
If I’ll go back to the beginning, the question I’ve been asked was “what’s the difference between a view and a component?”, and to make things even simpler, what does a generically made login screen any different than a Button component? Is it right to build a component using the presentation model architecture? Is the term “component” is relevant at all in Flex?
I, being myself, don’t react well when people are showering questions at me at the delicate time of the morning, stood up and claimed that “what do you mean? View is a view and a component is a compon…” but then I felt that something is not right in saying that. Why would you not develop a flex component using the presentation model architecture? As for now it seems to be more and more the right way to do it. It’s true that we have the AS building our UI so what? Why not take the logic and states apart from it?
I’m still pondering on it and would very much like to know what you think about this issue
Cheers.

June 02, 2009

My First Take on Flash Build 4

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

תראו, בסופו של יום, מרבית השינויים שנעשו בסביבת הפיתוח, היא הבילדר, הם עוד מספר צעדים לעבר הפיתוח הנוח באקליפס, למפתחי ג'אוה. יש עדיין כברת דרך לא קטנה, אבל אני, אישית, מרוצה מההתקדמות המתונה הזו. שכן נאמר כבר בעבר, לא חייבים לצעוד אחרי ג'אוה כמוקיונים סומאים, שכן, אחרי הכל, כש-Sun ז"ל באה לכתוב UI מה שיצא להם זה סווינג (ועכשיו JavaFX, שרק על זה רמי ורד יכול להעלות ערב שלם, ולשם שינוי לקרוע מצחוק).
בנינו, ה designer-developer workflow לא ממש העיף לי את הפטמה (אם להיות עדין). זה נחמד שיש את האפשרות לייצר ממשק, לגזור ממנו את הרכיבים ולחולל MXML בעזרתו. האם זה עוזר לי ועוד להרבה מפתחי RIA בעולם? אני בספק. אני חושב שהכלי הזה, Catalyst, יכול לשכון בכיף תחת הקטגוריה של "מוצרים שיביאו עוד מפתחים אלינו (Adobe)", שזה סבבה ובהחלט הכיוון הנכון, אבל לא ממש מרגש את מי שמפתח, אוהב ונוח לו עם סביבת הפיתוח של אדובה. מעבר לכך, אני לא ממש סומך על מחוללי קוד (עוד מימי Dream Weaver) כך שאני לא ממש רואה את עצמי עובד עם Catalyst על בסיס יומי.
השינוי המהותי עבורי נמצא יותר בין הקירות של ה IDE. הנה כמה דברים שדוקא כן מעיפים לי את הפטמה, ונכנסים לקטגוריית "הגיע הזמן באמת!":
Move Refactoring – למה זה לא נכנס בפלקס 3? אללא יודע...
Conditional Break Points – חן חן, ביחוד בפלאש, זה כל כך חשוב.
Getter/Setter generation, למרות ש... נו באמת, יאללא שיהיה.
Event Code Generation – תודה לכם שחסכתם לנו את הסיזיפיה הזו.
ASDoc – עכשיו כמו JavaDoc, יופי טופי.
Unit Testing – וואו! לא, לא... באמת וואו. מובנה בתוך ה IDE, מחולל מחלקות Test. כל הכבוד!

זה ברמה של הפיתוח. אני יודע שיש עוד, ואני אפילו לא באמצע השיטוט, אבל עדיין, זה מספיק לי.
מעבר לזה, כל מי שעובד עם Data Services ישמח לדעת על דברים כמו:
Network Monitoring – מה קורה לכם? לנטר אחרי התקשורת server-client ב IDE? ענק!
Data Management within the client – תשמעו, זה פשוט גדול. אני יודע שאנחנו בזבזנו לא מעט זמן לפתח משהו שכזה בקליינט, מה שהיום בשתי לחיצות עכבר וקפה עושים.
Defining Data Services Model – החיבור הפשוט ל BlazeDS וחבריו... מרגש, באמת מרגש.

די והותר, לא? כן, אני מבסוט בינתיים.
עכשיו, יש את כל החידושים והמצאות של ה SDK, שלא ממש הספקתי לרדת לעמקן, אך הם כבר הספיקו לעצבן אותי, עם namespaces כמו "s" עבור Spark, ועצם העובדה שקונטרולים מסויימים יופיעו כבחירה רק אחרי שלחצת בפעם השנייה על Ctrl+Space. "הם" רוצים שקודם יוצגו לך הרכיבים ש"הם" מעדיפים שתשתמש בהם. סבבה, אבל מעט לא בוגר. אדובה צריכים לצאת מנקודת הנחה שמפתחים שלהם כבר לא באנריסטים, והם יודעים מה יש ומה אין ובמה ירצו להשתמש.
העניין החדש עם ה States לא ממש מרגש אותי. זה היה ועדיין נשאר משהו שמאוד לא קל לנהל, מאד Hard-Coded ו... הממ... לא, לא עשה לי את זה. מה? הם באים לי אם האפרה של קוד שיהיה לי יותר ברור בעין? נו מה... אתם ילדים?

בכל אופן, זהו לעתה. אני מאד מרוצה בכללי עד כה, ואני בטוח שיש גם הרבה מפתחי ג'אוה מתוסכלים שסופקים כפיים ומרימים מבט לקוד האהוב עליהם בתודה. יש מצב לעוד טרוניות מצידי אז תפקחו אזניים.
יאללא ביי.

June 01, 2009

Flash Builder 4 (Beta) is a go

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



Well, it's about freaking time, ain't it?
At last, the Beta version of flash Builder 4 is out (or the 1st? wait... 4th? hmm... when was the 3rd?... nevermind). go ahead, download it, you nerds!~
There is more to download, like the HP QTP Extensions among others but I'm guessing that you'll be able to find it on your own, lads :)
have fun!

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.

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

March 26, 2009

OT: הופעה שלנו באוזן-בר

An English translation is available for this post...
מה המצב?
אז ככה,כמו שחלקכם אולי יודע יש לי הרכב (להקה קוראים לזה, אבל נו... מה עכשיו?) שנקרא "Typo". אתם יכולים לשמוע קצת צלילים מחזרות ב- MySpace שלנו. הסיבה שאני שם את זה פה היא שאנחנו מעלים הופעה ב-3 לאפריל, 2009, שזה יוצא יום שישי,באוזן בר, ככה לקראת חצות שכזה. זו הופעת טרום בכורה, קצרה וקולעת וחשוב מכל - חינאמית. אז אתם יכולים להתייחס לזה כהזמנה אישית.
בכיף.
יאללא ביי.
How's it going?
So as some of you might know, I have a band called "Typo". You can some of our stuff from rehearsals we did on our MySpace spot. The reason I'm telling you this is that we're giving a show on April 3rd, 2009, in a place called The Ozen-Bar, close to midnight. It will be a pre-premiere (… right) show, short and to the point and most importantly - free! So you can take this as a personal invitation.
Cheers.

February 21, 2009

You open, You see :: Label

An English translation is available for this post...
בהמשך ל"פותחים רואים" הפעם אני אתעכב על class שכולנו משתמשים בה תכופות ויכולה לעיתים למרוט את העצבים שאנו שומרים רק להפסדים של נבחרת הכדוריד של טורקיה: Label.
למי שלא מכיר, הקדמה קלה – Label זו מחלקת UI שבאה להציג טקסט בשורה אחת עם היכולת הנהדרת של חיתוך הטקסט במקרה ואין מספיק מקום עבור כולו, שירשור עם "..." ויצירת tooltip עם הטקסט המלא. זו פונקציונאליות לא רעה, בייחוד אם רוצים להציג מידע ב- DataGrid למשל, ומעוניינים בהתנהגות שמגדירה כי ברגע שמצמצמים רוחב של עמודה המציגה טקסט, הטקסט יחתך עם "..." ו- tooltip יופיע עבורו.
אז הנה שני דברים מעניינים שגיליתי תוך כדי נבירה במחלקה:
הראשון, אם נביט במתודת updateDisplayList נגלה שיד נסתרת מירקרה (ניטרלה את הקוד כהערה) האחראי ליצירת צבע רקע עבור ה Label. מדוע? לא ממש ברור, ואני יודע שיש מספיק חנאנות שבנו מגדלים רבים בכדי לספק ל- Label שלהם רקע, אז סאחבק הרים את הכפפה המעופשת והרחיב את המחלקה. לא עשיתי הרבה, שכן הקוד היה כבר שם. אני אשמח לדעת אם יש סיבה מסויימת לכך שהוא מורקר. את הקוד תוכלו למצוא בסוף הפוסט.
הדבר השני, שהטריד אותי הרבה יותר, הוא באג תמוה ומכעיס שיש ל- Label ושנוגע בדיוק בפיצ'ר המגניב שהזכרתי לעיל. אני אסביר: נניח שיש לנו container ברוחב מסויים ותחתיו יש לנו Label עם רוחב של 100 אחוזים. הדבר יתבטא בכך שה- Label יקבל את הרוחב של ה container. נקטין את ה container נקטין גם את ה Label, אתם מבינים את הרעיון. באופן מוזר, ברגע שלא מוגדר ל Label רוחב פיקסלי מוצהר, הטקסט שבתוכה מרחיב אותה בלי להתחשב ב- container בו היא נמצאת. רציתי לברר את הסיבה למחדל הזה שגורם לנו לפעמים ליצור כל מיני workarounds מטורפים (שגם שעולים בביצועים) ולמצוא פתרון יותר אלגנטי עד שהחבר'ה שם למעלה יתעוררו.
הסיבה למחדל הזה נעוצה בחישוב ה- explicitMinWidth של Label. כפי שאולי ידוע לכם, את המאפיין explicitMinWidth אנחנו לא מגדירים ישירות אלא ע"י השמת ערך למאפיין minWidth, מה שאומר שאם לא מגדירים minWidth אזי ה explicit min width לא מוגדר. תוסיפו למשוואה את העובדה ש- explicitMinWidth נדרש עבור חישוב גודל "הילדים" של container ויש לכם כבר שלושת-רבעי התשובה.
Label מחזיקה את UITextField בקומפוזיציה וזו אחראית (היא וכל אבותיה) על כל חישוביי הרוחב של תיבת הטקסט, חיתוך הטקסט וכיו"ב. כפי הנראה, ב- measure נעשה חישוב של רוחב תיבת הטקסט נכון לטקסט שבתוכה וגם ה minWidth מוגדר עפ"י אותו הגודל, משמע, היה לנו טקסט שרוחבו הסתכם ב 480 פיקסלים לצורך העניין, גם ה- minWidth של תיבת הטקסט יוגדר כ 480 פיקסלים. ואם ה minWidth מוגדר כך, אזי גם explicitMinWidth מוגדר כך. אין סיכוי שתיבת הטקסט תצטמצם נכון לcontainer שמחזיק אותה שהרי יש לה הגבלת מינימום של 480 פיקסלים. מרגש, לא?
בד"כ זהו המקום להוציא שלל דימויים עבור מי שקודד את האיוולת, אך במקום זאת אני אפנה לפתרון המיידי והפשוט. ברגע שאתם רוצים שה- Label יסונכרן ברוחבו ל container שמגדיר אותו, יש להגדיר את ה minWidth שלו ל-0. שכן, ברגע שמוגדר כבר ערך עבור explicitMinWidth פעולת ה set של minWidth פשוט לא עושה דבר. זה הכל.
אני מקווה שהשכלתם ומעתה תדעו יותר על מה שקורה בתוך Label. עד הפעם הבאה, עם מערכת חיסון חזקה יותר מכל הבחינות.
תיסלם.


In continue to “you open, you see” series, this time I’m going to talk about a class that we all know and use very often, yet it has the potential for killing us slowly as a result of a nerves breakdown: the Label.
For those of you who have no idea of what I’m talking about, here’s a quick brief – Label is a UI class that represents a text in a single line with the great ability to truncate that text if the space doesn’t allow all of it, adding a “…” suffix to it and a nice tooltip with the full text in it. This functionality is not bad at all, especially when you want to display a textual data in a DataGrid, and have a behavior that when the column is reduced in width, then the text within it will be truncated with a “…” suffix and a nice tooltip.
So here are two interesting things that I found out digging in that class:
The first, if we look at the updateDisplayList we shall find that a mysterious hand has removed the code that was assigned to handle coloring the background of the Label component. Why? Heavens knows. I do know that many geeks have built many extensions to overcome not being able to color the background of Labels, so I’ve decided to take this small opportunity and extend the Label class. Actually, I didn’t do that much. The code was already there, but commented out. I’ll be glad to know if there is a reason for commenting this out in the first place. You can find the code at the end of this post.
The second thing that bothered me even more, is the weird and annoying bug that Label has right where the nice feature I mentioned above is. I’ll explain: Say we have a Container bearing a certain width and residing in it we have a Label with the width of 100%. This means that if we reduce the width of the Container then the Label’s width will act accordingly and be reduced as well. Strangely, when you don’t set a specific pixel width to the Label, the text inside it stretches it without caring about the width defined on the parent Container. I wanted to realize why this happens, this which cause us sometimes to come up with weird workarounds (that are also expensive performance wise), and find a more elegant solution to it until the guys upstairs wake up (maybe they did, in Gumbo?).
The reason for this bug is due to the calculation of the explicitMinWidth member. As you might know, we can’t directly set the explicitMinWidth member, but instead we define it by defining the minWidth member. This means that if you don’t define the minWidth then you’re not defining the explicitMinWidth as well. Adding to this equation the fact that a Container relies on explicitMinWidth to measure its children and you already have three-fourths of the solution.
Labels holds UITextField in composition, which is responsible (with its ancestors) for all the text field sizing calculations, text truncations and the rest. As it seems, the width calculation of the Label’s text field is done within the measure method of the Label class. Inside that method the minWidth is set for the component according to the text measurement I’ve mentioned before, so if our text width is 480 pixels, the minWidth of the Label component is set to 480. If the minWidth is set to 480 pixels so is the explicitMinWidth. There is no way that the parent Container of the Label will be able to cast it’s width on it, since we have a 480 pixels minimum width constraint on it. Exciting, isn’t it?... oh man.
Usually this is the place I reach for the sickest metaphors I have in order to describe to ones who coded this monstrosity, but let me spare you with that and go directly to the simple solution. When you want the Label to be in synch with its parent Container width, simply put 0 as it’s minWidth because, when there is a value set to the explicitMinWidth the minWidth setter does nothing. That’s all.
I hope this helps you and you now know a bit more about what’s going on inside the Label class. Until next time, take care, guys.

package com.flashmattic.underthehood.labelex {
import flash.display.Graphics;

import mx.controls.Label;
import mx.styles.StyleManager;


/**
* Color of the Label object's opaque background.
* The default value is undefined,
* which means that the background is transparent.
*/
[Style(name="backgroundColor", type="uint", format="Color", inherit="no")]

public class LabelEx extends Label {
public function LabelEx() {
super();
}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);

var g:Graphics = graphics;
g.clear();
var backgroundColor:* = getStyle("backgroundColor");
if (StyleManager.isValidStyleValue(backgroundColor))
{
g.beginFill(getStyle("backgroundColor"));
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
g.endFill();
}
}
}
}

February 05, 2009

Flasher :: New Mag

An English translation is available for this post...

כן, אני יודע ששוב לא כתבתי הרבה מאד זמן, אבל שלא יעלה מורא בליבכם – אני המשכתי לכתוב קוד כמו ילד שדופקים לו מכות בין ביס לביס בפיתה של ארוחת עשר.
'תכלס, כל מה שאני בא לומר הפעם הוא, שמצאתי איזה מאגזין פלאש/פלקס חמוד לאללא שעשוי גם לא רע בכלל (יחסית לחובבן) ו... ואללא, שווה צפייה. יש שם ראיונות עם אנשים טובים שעושים קוד טוב, יש שם דאחקות וצחוקים של חנאנות יש שם מידע כמובן. תנסו: Flasher.

Yeah, I know I haven’t been writing for tones of time but fear not for I still coded my arse off like a beaten up boy at school lunch break.
All in all, all I came to say is that I found this nice new Flash/Flex Magazine on the web which pretty cute, nicely made (even for an armature mag maker) and… worth a look. There are some nice interviews with people from the scene, some geeks laughs and information of course. Give it a go: Flasher.

November 22, 2008

? Who asked the profiler to butt-in

An English translation is available for this post...

אחרי תקופה קשה בה הבריאות הרופפת שלי החלישה כל נים אפשרי, החלטתי שהגיעה העת להעיף מבט שוב למחשב ולבטל איזה מעופף טורדני שהקפיץ לי exceptions בדיבאג.
מה שקרה הוא, שבכל פעם שבאתי לדבג, עפה לי הודעה שה- profilerAgent.swf לא מצליח להתחבר בעקבות בעיית security sandbox, בעוד אני יושב שמוט לסת ולשון כששאלה אחת רצה 100 מטר משוכות בראש שלי: מי בכלל, לאלף עזאזלים, ביקש מהפרופיילר הזה להרים ת'ראש שלו?!
אמרתי לעצמי, שעכשיו אני מגגל על זה ומוצא את ההסבר לתופעה. תופעה, שאגב, החלה ברגע ששדרגתי לנגן 10 הידוע יותר לשמצה בכיניו "אני עוד אגיע לכל הפיצ'רים שלך, רק תן לעבוד קודם". פי-פאם-פו היגעתי לאיזה פוסט מעניין ששמט לי את הלסת עוד יותר, בבקשה לקרא.
נו? מה תגידו?
מסתבר שנשארה שורה בקובץ ה mm.cfg (ההוא שרושם לוגים של פלאש אם הוא ממש במצב רוח טוב). שורה פשוטה שאומרת לפרופיילר להרים את הראש שלו ולנסות להתחבר, בלי שום קשר לאם ביקשנו או לא. כמה פלקסי מצידו, הא?
אם מוחקים את השורה הזו הכל חוזר לסורו. כאשר מרימים את הפרופיילר, השורה נרשמת שוב וכאשר מרימים רק את הדיבגר, השורה הזו נמחקת כלא הייתה.
אז בכל מקרה, אם נתקלת בגוגל-מוגל הזה, אתם יודעים מה לעשות.
שבוע טוב.

After a long time in which my poor health has weakened any possible vain, I’ve decided that it is time to have a filtering glimpse over my PC and deal with some flying annoying pest that keeps on popping those exception windows when I debug.
What happens is that every time I debug, an exception pops up that the profilerAgent.swf can’t connect over a security sandbox violation (don’t you love it?). While I’m still on my chair with my mouth wide open, one question kept racing the marathon in my head, going: who, for flex sake, has asked to profiler to raise its head and connect?!
I decided that it’s time to google that pest and find the solution for this phenomenon, a phenomenon that BTW begun the moment I upgraded to Player 10, better known by the name of “I will get to all you feature, just let me work first”. After a few searches I came to some interesting post that got my mouth to open even wider. There you go, read it.
So? What can you say about that, huh?
As it appears, there is a lost line left on the mm.cfg file (you know, the one that registers flash logs if it’s in a really good mode). This line simply tells the profiler to raise its head and connect, regardless if we’ve asked for it or not. How Flexi of it, right?
If you delete this line then all goes back to normal. When the profiler is bootstrapped the line registers again and when the debugger is bootstrapped then the line is erased.
So anyhow, if you encounter this lovely swamp you know what to do.
Have a great week.

November 12, 2008

OT: ירושלים

אני לא אתחיל לקדוח לכם בשכל על כמה אני אוהב את העיר הזו, אני פשוט רוצה להעיף איזה גיץ של שמחה על בחירתו של ניר ברקת כראש העיר של הבירה שלנו.
לפעמים זה נשמע אבסורדי, אני יודע... "ירושלים, בירת ישראל" שתכלס אנחנו יודעים שהיא, גג, בירתם של כל אלו שלא הצליחו לנוס על נפשם ממנה, ואלו שעסוקים בלהניס אותם. הצביון החרדי שהעיר החלה לקבל עוד מימיו של אולמרט פשוט גרם לעיר היפה הזו לאבד לפחות 6 קבין של יופי. זה רק הולם את העם הבוחר שלנו, לקחת סיפור כישלון במישור המוניציפלי כמו אולמרט ולהעביר אותו למישור הלאומי. משם עברנו ללופוליאנסקי שתרם רבות לעיר בכך שהחליף את שלט הכניסה לירושלים בחתיכת פח-צפרדע ירוק ושעון כניסת-שבת. הרכבת העילית עדיין מחכה כמו העבודת שורשים שלי, שמישהו יסיים אותה ודי. זה היה די ברור לבוחרים החילוניים בעיר הקודש, שאם הם לא יצאו מהספות אח-גדול שלהם העיר הזו תהפוך במהרה לסרט המשך רע לבני-ברק.
ניר ברקת? לא ממש יודע כמה הוא יכול להרעיד את האדמה הקדושה של העיר ולהפיח בה חיים, אבל אני בטוח שהעיניים שלו נשואות לכיוון הזה. בוא נתחיל בלעודד בניית מפעלי הייטק בעיר הקודש, ליצור איזשהו כוח משיכה לצעירים לחזור לעיר ולהקים בה חיים. בוא נסיים את הרכבת המזדרגגת הזו ונפתח כבר את רחוב יפו (וכמובן נשלם פיצויים לבעלי העסקים שם, שפשוט דרכו עליהם כמו על בדלי סיגריה). אני לא מצפה שעכשיו אדון ברקת ינהל את העיר כמו צ'קפויינט, אבל עדיין... שיכניס מעט ענווה ויוקיע את השחיתות החרדית (כן, קראתם נכון) שהתנהלה בעיר עד כה. שחברי מועצה יכבדו אחד את השני.
אם התקוות יתממשו, יש מצב שאפילו עבדכם הנאמן ישים את ירושלים כאופציה, וכמוני עוד לא מעט שנשבר להם הפופיק מהתחליפים הזולים והמלוכלכים שיש למדינה להציע.
מר ברקת היקר, לא נותר לי אלא לצטט את שמגר מ"גבעת חלפון" ולומר: "לעסק, סרג'יו, לעסק...". וקריאת "יש!" קפוצת אגרוף של מי שאוהב את העיר שלו, לא בגלל דוד המלך, אלא בגלל שנולד שם.

November 03, 2008

ServiceAdapter in BlazeDS – Where’s the service?

An English translation is available for this post...

"כיף".
לו הייתה ניתנת לי מילה אחת בכדי להגדיר את המעבר מ-LCDS ל-BlazeDS הייתה בוחר במילה הזו – "כיף". טוב נו, זה לא כזה נורא, אבל עדיין אדובי מצליחים להכשל בעקב אכילס שלהם שוב: הדוקומנטציה.
למרות שהכל די שקוף לאימפלמנטור (אני, אני...) ומעבר להברחות jar-ים מפה לשם והגדרות תלויות, מגיעים לשינויי-קוד, שהם למעשה הכואבים מכל.
בזמנו יצרתי הרחבה של ActionScriptAdapter עבור יישום של צ'אט באפליקציה. אותה המחלקה ניהלה את ההודעות בצורה מעט שונה שלא רלוונטית לעניין כרגע. מה שכן, המחלקה השתמשה במשתנה שהגיע אליה בירושה מאדון ServiceAdapter שנקרא בפשטות service.
קימפול זריז וג'אוה צועקת שהיא לא יודעת מי זה service ולא מכירה אותו אפילו ב"שלום שלום". מיד כשועל מנוסה אני קופץ אל התיעוד של אדובה בכדי לגלות מה העניינים. אני אכן מגלה שאין חיה שכזו service ב- ServiceAdapter, אבל להפתעתי אני מגלה דוגמת קוד שעדיין משתמשת בו כאילו כלום לא קרה. לא מאמינים? הנה תראו. אז מה בעצם נותר לנו? נכון. לפנות לפורומים.
חיפוש זריז ואני עולה על הת'רד, בו נאמר כי שהדוגמה היא קלוקלת ולמעשה יש דרך אחרת לפנות ל- service הנעלם.
אני מאד מקווה שאדובה מודעים לאיוולת הזו, שבטח מבזבזת לא מעט זמן למפתחים ברחבי העולם.
עד העונג הבא.

“Fun”.
If I had one word to define the migration from LCDS to BlazeDS, I would choose this word – “Fun”. Well, it’s not like it’s all that bad, but still Adobe manages to fail when they are known to fail in the most: Documentation.
Even though that most of it is pretty transparent for the implementers (me, myself and I…) and after smuggling all the .jar files and messing around with dependencies, we reach to the code migrations which hurt the most.
At the time I’ve created an extension for ActionScriptAdapter for a chat in the application. This class managed the messages that came through it in a slightly different manner that’s not relevant to the story. What’s relevant is that this class used an inherited variable called “service” that came from Mr. ServiceAdapter.
A swift compilation and Java shouts that it doesn’t know who “service” is. I instantly dive into Adobe’s documentation to see what the hell is done wrong here, and I do find out that there’s no such thing as “service” on ServiceAdapter, but to my utter surprise I also see a nice code sample which uses it. Don’t believe me? See for yourselves. So what have I got left? That’s right… forums.
After a quick search I find this thread where it says that the code sample is wrong and misleading and there’s another way to reference the “service” variable.
I very much hope that Adobe is well aware of this mistake that surely waste time to a lot of developers around the world.
Till next time…

October 26, 2008

Date Formatter gets hours wrong

An English translation is available for this post...

משהו ששווה לזכור.
לאובייקט Date, ברגע שרוצים להציג אותו בצורה מעט יותר עדינה מ- timestamp, משתמשים ב- Formatter שיודע לקבל format string ומשם לפרמט אותו לפיו. אתם יודעים על מה אני מדבר - MM:DD:YY וחבורתו.
הקטע קטע מגיע שאנחנו רוצים לפרמט את השעות. את השעות אפשר לפרמט, בין היתר, בדרכים הבאות: HH, ו-JJ.
HH, מספר לנו על יום שבו השעות הן 1-24, בעוד ש-JJ מדבר על יום שבו השעות רצות מ 0-23.
זה נכון ש-HH תהיה הבחירה האינטואיטבית של כל בר-דעת (שכן, מה בדיוק JJ אמור להביע, just-joking?), אבל אם תבקשו HH, לעיתים תכופות תגלו שזה לא ממש מה שהתכוונתם אליו, ופתאום יש לכם הבדל של שעה סוררת. זה קצת מקומם אם לקוח שלכם אמור להגדיר פורמט בו הוא רוצה לראות תאריכים, ומגלה שהשעון לא מכוון, כי הוא חשב (ובצדק, לעזאזל! בצדק!) ש-HH זו הבחירה הנכונה.
אדובה...? רוצים לספר לנו משהו שאנחנו לא יודעים?

Here’s something that is worth remembering.
When you want to display the Date object in a more easy-to-understand manner than timestamp, you use the DateFormatter that receives a formatting string ant act accordingly. You know what I’m talking about – MM:DD:YY and their gang.
The trouble comes where we want to format the hours as well. This can be easily done, mong other formats, in these ways: HH and JJ. HH will be a day where the hours go from 1 to 24 and JJ will be a dat where the hours go from 0-23.
It’s true that the intuitive selection of anyone who claims to have a brain would be HH (since, what exactly does JJ stands for, Just-Joking?), but if you ask for HH in your format string you will often find that it’s not really what you meant for and suddenly you have a one hour difference. To be honest, it pretty annoying when one of your customers is trying to define her own date format, only to find that the hours are not synched, cause she thought (rightfully, god-damn, rightfully!) that HH is the right choice to make.
Adobe? Care to tell us something we don’t know?

October 05, 2008

OT: ההופעה של AIR

כן, עוד OT. אל חשש, יש בדרך כמה פוסטים שיזגגו כל עין של מפתח תוכנה נחנח. יהיה בסדר...
ומה על הפרק? ההופעה של AIR, שהתקיימה ביום חמישי שעבר והייתה מפח-נפש עדין.
נתחיל מהיסטוריה - את AIR אני מכיר פחות או יותר משנת 98' של המילניום הקודם. התקליט שלהם, Moon Safari נטחן במקום העבודה שלי דאז, עד שלבסוף ייבש לשאר הקולגות את הנוירונים. מה אני אעשה? הנעימות שלהם הזכירו לי שני דברים שקרובים מאד ללבי: פינק-פלויד ו- Atari.
אני לא חשבתי שהם יגיעו לארץ, וגם אם המחשבה הזו חמקה בזריזות למוחי, לא ממש האמנתי שאני אלך להופעה שכזו. בכל אופן, נפל דבר ומצאתי את עצמי צובא על דלתות האנגר 11 בנמל, יחד עם האנשים היפים של תל-אביב. כרגיל ולפי המתכונת, התור לכרטיסים היה מאורגן כמו גשר המכבייה. פה שם, נכנסנו לאולם הגדול וחכינו לייבוש הגדול הנקרא "מתי הם יעלו כבר, יא אללא שלהם?". סביבות 22:45 הם עולים. שלושה חברים, שני צרפתים מהודקי חולצה ומכנס ומתופף שמנמן.
ההופעה התחילה עם שיר שלא הכרתי (אבל אין דבר, עוד הרבה כאלו יגיעו...), במין פסנתר, גיטרה, תופים שכזה. סתם. שאר ההופעה נמשכה בין שירים מוכרים יותר לפחות, בלי הרבה פירוטכניקת-אורות (אם בכלל) ופחות מזה כריזמה של הזוג. שני הצרפתים בקושי דיברו עם הקהל, וכשעשו זאת, השתמשו באפקט ה"רובוט" שיצא מהאופנה בערך בזמן שתמי בן-עמי (ז"ל) הייתה רלוונטית. ומילא להשתמש בקול הרובוטי פעם אחת, אבל לשמוע שוב ושוב "Thank you Tel-Aviv" ככה... ראבק בנאדם, תקנה לגו, רק עזוב אותנו.
ככה נעמדנו בין השירים, בלי להתרגש יותר מדי והאזנו לסאונד הנוראי שהאנגר 11 יודע לייצר. אני לא מבין איך אפשר לנהל שם הופעה. גם כשהייתי בפרודיג'י הסאונד היה נוראי שם. לא למדנו שום דבר? יש מצב שהאנגר, שהוא למעשה אולם-פח, לא ממש מתאים להופעות בהן כל תו חשוב? ונגיד שהיה סאונד סביר, אוקיי? הצמד השמיט המון "קטנות" מהשירים. "קטנות" שעושות את השירים והקטעים למה שהם. זה היה כמו גרסאת כיסוי מאד מהוקצעת, אבל חוטאת למקור.
איכשהו הגענו להדרן הראשון. מחיאות כפיים ושריקות מקהל שבאמת בא לתת את כל מה שיש לו ונתקל בשני באגטים עבשים (ומתופף שמנמן), והנה הם עולים ומבצעים שירי צאן-ברזל כשהם מסיימים ב- La Femme d'Argent, ורק שם הם נתנו את מה שהקהל רצה מתחילת ההופעה: "בום!". הפציצו בפסיכודליה, העיפו את התאורה לאוויר, יצאו באילתורים וזה בדיוק מה שהיה חסר כל ההופעה!
ואז הם ירדו.
אשכרא הדליקו את הקהל, נפנפו לנו מול הפנים ב"תראו מה יכל היה להיות אם לא היינו זורקים עליכם" וירדו מהבמה. שום תשואות לא החזירו אותם חזרה, ותכלס? אם היה לי בקבוק בירה ביד, אולי הוא היה מוצא עצמו במאך 5 לכיוון הבמה. 75 דקות של הופעה מאכזבת עם שיאים של גג משגל-פנסיונרים. שיקחו את קול הרובוט שלהם ואת המתופף השמנמן ויגלשו על טיל הישר לצרפת. עדיף לשים דיסק באוטו.
בהחלט אכזבה. AIR הם לא הרכב של הופעות (לפחות לא בארץ) ושימשיכו לעשות את מה שהם עושים טוב, ולא לגבות כסף על חזרות עם קהל.
עד העונג הבא.

September 29, 2008

OT: שנה טובה לדוד גיבור

מה קורה, מתקתקי-קוד אפרפרים?רק רוצה לאחל לכם שנה טובה, אבל לא שנה טובה של החברים שאתה לא רואה מאתיים שנה, ופתאום מפליצים לך SMS קבוצתי של "אושר והגשמה", אלא שנה טובה מהלב, וזה הולך ככה:
קודם כל בריאות, שזה חשוב וגם קופ"ח חונקת בכספים, אז חבל... ואז אחרי הבריאות שיבוא גם האושר, אבל אושר אמיתי שבא מיצירה, או אהבה או... בורקס טוב. סביח זה לא אושר, סביח זו מלחמה קולינארית. איפה היינו? אה! ממון, כי זה נחמד שיש מרשרשין בכיסים, לכל המשקיעים בבורסה אני מאחל שנה נטולת ריצות אחר הזנב של עצמכם, שתמצאו במה להשקיע ושתפסיקו להאמין שלדבר על כסף באמת עושה כסף. אהבה זה חשוב, אז שהאהבה תהיה שם, לא פושרת, לא דרדל'ה, אלא ממש אהבה כזו שמותחת חיוך גם על איטונג. ולאלו שכותבים קוד, שתהיה לכם שנה של פחות re-factoring, שנה של פחות באגים ויצירתיות. ולמוסיקאים שבנינו, שנה של פלייליסטים שווים, חוזים בחו"ל והופעות מלאות.
שמחות על ראשיכם,
חג שמח ושנה טובה!

September 20, 2008

Custome Metadata tags for Flex :: keep-as3-metadata

This Hebrew message will be followed by an English one...

הטריף לי את השכל, הקטע הזה, הארגומנט הממזר הזה של MXMLC (ו- COMPC) שנקרא בפי חבריו: keep-as3-metadata. אם תקראו בקצרה בדוקומנטציה (שכמו תמיד לא מאכזבת ולא מספרת שום דבר יעיל) תלמדו שאם אתם רוצים לשמור תגי metadata שלכם, כך עושים זאת. לא ממש מפרטים מי, מה, איך להוציא את הפרטים של אותו התג ב-runtime... לא... למה שפרטו? אנחנו, כרגיל, ננחש.
האמת? את העניין גיליתי תוך כדי הצצה לעבר framework שנקרא Swiz (שווה הצצה, אבל לא מספיק בכדי לצאת לרחוב בצעקות "הידד!"). ב- Swiz משתמשים בשני תגי metadata של ה- framework שהם לא קשורים לאלו המוגדרים מראש בפלקס, וזה הביא לי בסקרנות – האימפלמנטציה, השימוש, אז פתחתי ונברתי מעט בקוד של Swiz ויש לפני את הבשורה.
לפני שאני אפרוש פה קוד, אציין שהשימוש, במתכונת הנוכחית, הוא מעט בזבזני ולא אלגנטי. אני מקווה שבעתיד תהיה אופציה הרבה יותר טובה ליישם את העניין. ובכן, לעסק:
ראשית, בואו רגע נתעכב על ()describeType. המתודה הזו יודעת לקבל אובייקט ולהחזיר אובייקט XML עם כל המאפיינים ה- Public של אותו אובייקט. ה-XML הזה גם מכיל גם את ה-metadata עבור כל מאפיין. יש כמה וכמה כלים לפלקס שבנויים על היכולת הזו. סבבה לנו? למה לא.
עכשיו, בכדי לאפשר את תגי ה-metadata הנוספים מוסיפים ארגומנט לקומפיילר העונה לשם keep-as3-metadta. כך שאם אנחנו רוצים להוסיף metadata בשם flashmattic, נכתוב:

-keep-as3-metadata+=flashmattic

למה =+? כי אנחנו לא רוצים להיות חצילונים ולמחוק את כל מה שכבר מוגדר.
מה שעכשיו קיבלנו הוא, שבכל הגדרה שנכתוב בה את [flashmattic], נקבל את את ערכי ה-metadata ב-XML של ה describeType. את ה metadata נכתוב כמו כל metadata אחר:

[flashmattic]
public var inputTxt:String;

אנחנו יכולים להוסיף גם מאפיינים ל- metadata, כך:

[flashmattic (value=”Matti”)]
public var inputTxt:String;

זה מגניב, אבל לא ממש עוזר לנו. את כל זה יכולנו לעשות גם בלי הטובות של הקומפיילר והארגומנטים שלו. או! אז פה הטעות, שכן מבלי להוסיף את הארגומנט המוזכר לעיל, הקומפיילר לא יודע לקרא את ה-metadata הזה ולהכניס אותו אל הפרטים ב-XML של describeType.
מה שנותר הוא לקרא את הנתונים הללו, להוציא מהם את מה שאנחנו מחפשים וכך, ב runtime נוכל ליישם dependency injection למשל. הנה אמפלמנטציה אחת לדוגמה:

private function resolveDependencies(accessorList:XMLList):void {
for each (var dependee:XML in accessorList) {
if (dependee.metadata != undefined && dependee.metadata.(@name== "flashmattic") != null) {
var meta:XMLList = dependee.metadata.(@name == " flashmattic");
if (meta.arg.(@key == "value") != null && meta.arg.(@key == "value").@value != undefined) {
trace(meta.arg.(@key == "value").@value); // Traces “Matti”
}
}
}
}

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


This little thingy drove me insane. That elusive MXMLC (and COMPC) argument, well-known to his fellow arguments as “keep-as3-metada”. If you read the documentation about it (that never loses an opportunity to fail in description), you’ll learn that if you wish to keep your own metadata tags, this is the way to do so. They don’t really say who, where or how to get those details at runtime. We’re left guessing…
To be honest, I first discovered interest in this issue when reading about the “Swiz” framework. In Swiz there are two extra customized metadata tags involved, and that made me curious about the implementation and usage, so I lifted the hood up and looked under it.
Now, before I give you my resolutions, I must admit that what Swiz is doing is a bit expensive performance-wise. I hope that this way of implementation will be made more elegant in the future of Flex SDK. Well… let’s dive into it:
First of all we want to check out this nice method called “describeType()”. This methods expects an object as its argument, and return an XML object with the details of all public properties in this object. By the way, Many Flex tools rely on this feature. Are we happy so far? Sure we are.
Now, in order to enable extra customized metadata, we need to add the keep-as3-metadata argument to the compiler, so say we want to add “flashmattic” as our new customized metadata, we’ll add the following to the compiler arguments:

-keep-as3-metadata+=flashmattic

Why +=? Cause we don’t want to be complete numb-nuts and override the predefined metadata tags.
What we have now is, whenever we add the flashmattic metadata tag to any public property of an object, the XML retrieved from the descibeType() method will include that metadata and it’s properties. We add the metadata to our like any other metadata in flex:

[flashmattic]
public var inputTxt:String;

We can also add some properties to our metadata tag, so… let’s add a property to our metadata:

[flashmattic (value=”Matti”)]
public var inputTxt:String;

This is nice, right? Yeah, but we could have done this without asking the favors from the compiler and its arguments. Wrong! Not adding the metadata to the compiler, will cause the descibeType() method to avoid it and not have its details to the XML.
What’s left for us is to run trough that XML at runtime, find our metadata and retrieve the information from it. This is highly useful when wishing to implement dependency injection in Flex. Here’s one example:

private function resolveDependencies(accessorList:XMLList):void {
for each (var dependee:XML in accessorList) {
if (dependee.metadata != undefined && dependee.metadata.(@name== "flashmattic") != null) {
var meta:XMLList = dependee.metadata.(@name == " flashmattic");
if (meta.arg.(@key == "value") != null && meta.arg.(@key == "value").@value != undefined) {
trace(meta.arg.(@key == "value").@value); // Traces “Matti”
}
}
}
}

Not bad, ah? Well, apparently, going through that loop looks a bit expensive as I mentioned before, but after running a couple of tests it looks like it will not affect the player that bad (16ms for 2 nested components), but I need to test it on a larger project to make sure that this implementation won’t add to the already bad performer we call Flash Player.