Flash CS4 Gotchas 03 November 2009
I’ve been banging my head against Flash for the last few days and started trying to document a few things.
Can’t import fl.controls
For some reason Adobe didn’t include them by default so you’ll need to add the path to the project.
- Open the File > Publish Settings… menu item
- Click the Flash tab
- Click the Settings… button
- Click the Source Path tab
- Click the + button and paste in:
$(AppConfig)/Component Source/ActionScript 3.0/User Interface
Can’t use a Tween on a scrollRect
The Tween class can only change a simple property and the scrollRect need to be changed and the reassigned before it will update. The solution is to add new property to the class and Tween that instead:
public function get scrollX():Number {
if (this.scrollRect) {
return this.scrollRect.x;
}
return 0;
}
public function set scrollX(value:Number) {
var r:Rectangle = this.scrollRect;
if (r) {
r.x = value;
this.scrollRect = r;
}
}
Then you can use a Tween:
tween = new Tween(this, "scrollX", Strong.easeOut, scrollX, scrollX + 100, 1, true);
Also, you’ll want to keep a reference to the Tween object so that it doesn’t get garbage collected half way through the animation.
Can’t use named HTML entities
Flash’s TextField only supports a small subset of named HTML entities (< > & " '
). If you’re displaying HTML from users or a CMS you’ll find that things like &deg;
slips by so you’ll need to convert the named entities to their numeric versions.
*Update: * I’d originally tried using PHP’s HTML entity table to build some ActionScript 3 conversion code but it turned out it was missing a lot of common entities like em and en dashes. To account for these I converted the Wikipedia’s List of XML and HTML character entity references into this format.
The framework for this code was taken from here.
<?php
public class HappyHtml {
protected static var numberedEntities:Array = [
'"', '&', ''', '<', '>', ' ', '¡',
'¢', '£', '¤', '¥', '¦', '§', '¨',
'©', 'ª', '«', '¬', '­', '®', '¯',
'°', '±', '²', '³', '´', 'µ', '¶',
'·', '¸', '¹', 'º', '»', '¼', '½',
'¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä',
'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë',
'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò',
'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù',
'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à',
'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç',
'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ',
'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü',
'ý', 'þ', 'ÿ', 'Œ', 'œ', 'Š', 'š',
'Ÿ', 'ƒ', 'ˆ', '˜', 'Α', 'Β', 'Γ',
'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ',
'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ',
'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω',
'α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η',
'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ',
'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ',
'φ', 'χ', 'ψ', 'ω', 'ϑ', 'ϒ', 'ϖ',
' ', ' ', ' ', '‌', '‍', '‎', '‏',
'–', '—', '‘', '’', '‚', '“', '”',
'„', '†', '‡', '•', '…', '‰', '′',
'″', '‹', '›', '‾', '⁄', '€', 'ℑ',
'℘', 'ℜ', '™', 'ℵ', '←', '↑', '→',
'↓', '↔', '↵', '⇐', '⇑', '⇒', '⇓',
'⇔', '∀', '∂', '∃', '∅', '∇', '∈',
'∉', '∋', '∏', '∑', '−', '∗', '√',
'∝', '∞', '∠', '∧', '∨', '∩', '∪',
'∫', '∴', '∼', '≅', '≈', '≠', '≡',
'≤', '≥', '⊂', '⊃', '⊄', '⊆', '⊇',
'⊕', '⊗', '⊥', '⋅', '⌈', '⌉', '⌊',
'⌋', '〈', '〉', '◊', '♠', '♣', '♥',
'♦',
];
protected static var namedEntities:Array = [
'"', '&', ''', '<', '>', ' ', '¡',
'¢', '£', '¤', '¥', '¦', '§', '¨',
'©', 'ª', '«', '¬', '­', '®', '¯',
'°', '±', '²', '³', '´', 'µ', '¶',
'·', '¸', '¹', 'º', '»', '¼', '½',
'¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä',
'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë',
'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò',
'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù',
'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à',
'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç',
'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ',
'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü',
'ý', 'þ', 'ÿ', 'Œ', 'œ', 'Š', 'š',
'Ÿ', 'ƒ', 'ˆ', '˜', 'Α', 'Β', 'Γ',
'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ',
'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ',
'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω',
'α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η',
'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ',
'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ',
'φ', 'χ', 'ψ', 'ω', 'ϑ', 'ϒ', 'ϖ',
' ', ' ', ' ', '‌', '‍', '‎', '‏',
'–', '—', '‘', '’', '‚', '“', '”',
'„', '†', '‡', '•', '…', '‰', '′',
'″', '‹', '›', '‾', '⁄', '€', 'ℑ',
'℘', 'ℜ', '™', 'ℵ', '←', '↑', '→',
'↓', '↔', '↵', '⇐', '⇑', '⇒', '⇓',
'⇔', '∀', '∂', '∃', '∅', '∇', '∈',
'∉', '∋', '∏', '∑', '−', '∗', '√',
'∝', '∞', '∠', '∧', '∨', '∩', '∪',
'∫', '∴', '∼', '≅', '≈', '≠', '≡',
'≤', '≥', '⊂', '⊃', '⊄', '⊆', '⊇',
'⊕', '⊗', '⊥', '⋅', '⌈', '⌉', '⌊',
'⌋', '⟨', '⟩', '◊', '♠', '♣', '♥',
'♦',
];
public static function decode(text:String):String {
var len:int = namedEntities.length;
for (var i:int = 0; i < len; i++) {
var entity:String = namedEntities[i];
var ch:String = numberedEntities[i];
if (text.indexOf(entity) > -1) {
text = text.replace(new RegExp(entity, "g"), ch);
}
}
return text;
}
}