Skip to content

Instantly share code, notes, and snippets.

@skovalyov
skovalyov / DateUtil.as
Created June 5, 2012 07:46
DateUtil class with getTimeSpan() method that formats the time span between now and the date specified in a "Facebook way"
package {
import mx.formatters.DateFormatter;
import mx.utils.StringUtil;
public class DateUtil {
public static const SECOND_IN_MILLISECONDS : int = 1000;
public static const FEW_SECONDS : int = 5;
@skovalyov
skovalyov / CarSpeedCheck.java
Created June 5, 2012 07:49
Car speed check
if (car.speed() > 2 * SPEED_LIMIT)
generateAlert("Watch out for cops!");
@skovalyov
skovalyov / TruncatedText.as
Created June 5, 2012 07:54
Text control with truncateToFit property support
package {
import mx.controls.Text;
import mx.core.UITextField;
import mx.core.mx_internal;
use namespace mx_internal;
public class TruncatedText extends Text {
@skovalyov
skovalyov / URLUtil.as
Created June 5, 2012 07:58
How to prevent pop-up blocking in Firefox
package {
import flash.external.ExternalInterface;
public class URLUtil {
protected static const WINDOW_OPEN_FUNCTION : String = "window.open";
public static function openWindow(url : String, window : String = "_blank", features : String = "") : void {
ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
@skovalyov
skovalyov / NavigateToURLPopUpBlock.as
Created June 5, 2012 08:00
navigateToURL pop up block
navigateToURL(new URLRequest("http://skovalyov.blogspot.com/"), "_blank");
@skovalyov
skovalyov / URLUtilOpenWindowExample.as
Created June 5, 2012 08:02
URLUtil usage example
URLUtil.openWindow("http://skovalyov.blogspot.com/");
@skovalyov
skovalyov / ExtendedFormItem.as
Created June 5, 2012 08:12
Left aligned label in FormItem
package {
import flash.display.DisplayObject;
import mx.containers.FormItem;
import mx.controls.Label;
import mx.styles.CSSStyleDeclaration;
import mx.styles.StyleManager;
[Style(name="labelAlign", type="String", enumeration="left,right", inherit="no")]
@skovalyov
skovalyov / TruncateToFitPerformanceProblem.as
Created June 5, 2012 08:14
truncateToFit() performance problem
while (s.length > 1 && textWidth + TEXT_WIDTH_PADDING > w) {
s = s.slice(0, -1);
super.text = s + truncationIndicator;
}
@skovalyov
skovalyov / AuthenticationManager.as
Created June 5, 2012 22:20
ActionScript singleton facade example
package {
public class AuthenticationManager {
public static var instance : AuthenticationManagerInstance = new AuthenticationManagerInstance();
}
}
@skovalyov
skovalyov / AuthenticationManagerInstance.as
Created June 5, 2012 22:21
ActionScript singleton implementation example
package {
internal class AuthenticationManagerInstance extends EventDispatcher {
public function AuthenticationManagerInstance() {
super();
}
public function authenticate(username : String, password : String) : void {
// Authentication routine.