ActionScript Array Duplication Explained
September 3, 2006
I was having some difficulties with copies of ActionScript Arrays.
I used to think that code like this
var a:Array = new Array(1,2,3);
var b:Array = a;
would assign a copy of a to b. Today I investigated that assumption. At first my assumption got strengthened by the discovery that there is no copy constructor for arrays and also no copy function in the Array prototype. But as I learned from working with Flash and ActionScript, first looks can be deceiving. Luckily looking some further I found a good explaination of ActionScript Array copying on kirupa. You can use the slice function to really copy arrays. Like this:
var a:Array = new Array (1,2,3);
var b:Array=a.slice();
And copying of a 2 dimensional would then go like this
var a:Array = new Array ( new Array(1,2,3), new Array(4,5,6) );
var b:Array = new Array();
for(var i:Number=0; i < a.length; i++) b[i] = a[i].slice();
Good to finally know how ActionScript Arrays work. Saves me a lot of trouble.
Some HELP on Flash 8 with ActionScript 2.0
August 24, 2006
When I started this blog, it wasn’t my intention to fill it up with stories/tutorials/complaints about Flash and ActionScript. But I’ve been doing a lot of Flash development lately so I came to write about it. Apparently I’m far from being the only Flash web-developer that searches the Internet for guidance. In this post are the ActionScript/Flash related search strings that made search engines guide visitors to my Blog in the last three days. Because I’m a nice guy, I want to help people that search for answers and so I’m gonna try to answer the questions behind the search strings. (If I can decipher what the question was.) I think that the original searchers have found their answers by now, but maybe someone else is helped by this.
I give my help in the format.
- SEARCH TERMS
My answer to what I think was the question.
My answers will primarily relate to Flash 8 ActionScript 2.0 because this is what I’ve been working with lately.
Okay here we go;
- Element MOVIE TITLE is undefined in FORM
My Blog is the first results when you Google on these terms but I won’t be able to help. I have no clue of what the questions is. So Google, please remove me, I’m probably of no use with such a high ranking! - flash timeline code
Probably looking for the possibilities of coding against the Flash TimeLine.
This is what I know of ActionScript related to the timeline.
There is the MovieClip property _currentframe which informs of which frame your MovieClip is currently playing.
There are the MovieClip functions gotoAndPlay and gotoAndStop. Both take as a parameter either a number representing the frame number, or a string representing the label of the frame, to which the play-head is sent. gotoAndPlay makes the playhead play from there gotoAndStop makes the play-head stop there. - put a blog inside a flash file
flash blog
blog inside a flash movie
“blogging in flash”
Nice! I wrote two entries about this subject. I hope this helps.
findability-and-linkability-with-flash
and
blogging-in-flash - average color in an image
color average image
image average color
This search does not have to have been Flash related, but for those interested I posted a piece of ActionScript code that calculates the average color in an image.
taking-color-average-from-image - removeMovieClip actionscript 2.0
This person probably had trouble using ActionScript to remove MovieClips. Flash only allows you to programmatically remove a movie clip instance if its depth is within a specific range. Any MovieClip with a depth between 0 and 1048575 inclusive can be programmatically removed. Any other MovieClip remains unaffected by removeMovieClip( ). I wrote a function that first swaps your MovieClip to proper depth and then removes it.
another-thing-thats-missing-in-actionscript-20 - finding inner child nodes length ActionS
I have to guess what this person was looking for. It might have been the XML support in ActionScript. XML support is one of the few things in ActionScript I’m enthusiastic about. They (Macromedia, now Adobe) really nailed that. Learning the XML API was absolutely painless. Here is an excellent tutorial: http://www.kirupa.com/web/xml/index.htm
The thing I like the best about Flash XML support is that XML are still parsed even when there slightly malformed. - htmlText embedded font
flash Textfield.embedFonts bug
flash actionscript embedded fonts
embedding fonts in flash
flash css embedded fonts
embedding a font in a text field dynamic
embedFonts ignores html text flash
“TextField.StyleSheet” + embedded fonts
Embedding Fonts in your Flash Movie is far from trivial. This is how I made it work for me.
embedding-fonts-in-flash
Okay so now you have your fonts embedded in Flash. I had the unpleasant surprise that embedding the font made some of my htmlText disappear. It turned out that I had to specify the font-family style attribute for every HTML tag I was using.
another-day-another-fight-with-flash - dynamicly
Funny someone found my blog using a spelling error as search term. What does that say about my blog?
- actionscript 2.0 type check String.prototype
actionscript string replace
actionscript “in string” function
actionscript 3.0 trim function
actionscript 2.0 string replace pattern
trim spaces in actionscript
flex textfield trim the textfield data
actionscript string trim
actionscript string replace pattern
string replace action script
string replace actionscript
Flash ActionScript replace function
actionscript extending string
replace function actionscript
actionscript string replace function
flash action script trim string
flash string functions replace
actionscript replace function
string replace action script
flash action script string replace
trim functions in actionscript
actionscript 8 string replace
actionscript string functions
as 2.0 String.prototype
actionscript 2.0 String.prototype and type
actionscript string
actionscript 2 indexOf
actionscript string
Whooha! Damn. I’m definitely not the only one missing some String functionality in Flash. For the String replace function you could use: originalString.split(replace_what).join(replace_with)
If you need more functionality I recommend bundling all the extra String functionality you need in a String Toolkit (a custom made class). I found ways to implement String trimming, String searching, String replacing and a lot more.
string-functions-macromedia-forgot
More-Advanced-String-Replace
This should get you started. If you not more String functionality, just ask, I might have it for you. - Flash Bezier Drawing
flash drawing
actionscript bezier curve
flash draw bezier curve
drawing paths in flash
movieclip.beginfill remove fill
drawing curves between nodes flash 8
draw curves actionscript flash
Flex 2.0 beginGradientFill
flash drawing api bezier
flash drawing api runtime
These search terms seem all related to the Flash MovieClip drawing API. This is what I wrote about the drawing API.
Flash drawing API
and specificly about Bezier curves
Flash drawing API bezier - flash actionscript string[] array
Looking for ways to create string arrays in ActionScript. Look no further.
flash-actionscript-string-array - draw line as underline flash actionscript
I’m not sure what this searcher was hoping to find. If you want to underline text, I recommend using a StyleSheet with text-decoration: underline; for the part of your text that you want to underline. Don’t use the drawing API for this purpose. To complicated. - “bitmap.draw()” flash
replace bitmap movieclip
You probably need the BitmapData class. Google on that search term you will probably find what you need. - flash blogger
Nope, I’m not a Flash Blogger. It is not my intention to Blog about Flash. I’ve been blogging a lot about Flash lately and that let many to my blog searching for guidance in using Flash. This kind of locked me up in this behaviour, but I will stop blogging about Flash as soon as my current Flash project ends. - as2lr
If your looking for the ActionScript 2.0 Language Reference PDF you can find that on Adobe’s webpage.
Documentation Page: http://www.adobe.com/support/documentation/en/flash/
Complete Flash 8 Documentation: flash_pdfs.zip
BTW as2lr.pdf is an excellent resource to start your every research on ActionScript features. - flash swapdepths puzzle piece
Yes swapping depths is another thing that has not been implemented very intuitively. All MovieClips you create must exists on some depth. The depth of a MovieClip determines how it’s stacked above or under other MovieClips. Depthnumbers are integer numbers that can not be shared by more then one MovieClip. In other words there can only be one MovieClip per depth. If you want to swap your MovieClips depth with that of another then this is possible. There is the function MovieClip.swapDepths() which takes the new depth for your MovieClip and place it in that depth swapping with whatever was there. When creating MovieClips you have to specify at with depth you want them. After that you can only change your MovieClips depth using swapDepths. MovieClip.getDepth() is used for retrieving the depth of a MovieClip and MovieClip.getNextHighestDepth() can be used to retrieve the “next-highest-depth-used-in-your-MovieClip” +1.
Whooha. Hope that clears some things up.
Dynamically create a Flash button from a MovieClip
August 24, 2006
To dynamically create a button (clickable MovieClip) with ActionScript you only have to define the onRelease event. For example this makes a button out of your MovieClip ‘MyMovieClip’.
class com.mywebsite.MyMovieClip extends MovieClip
{
function MyMovieClip()
{}
public function onRelease()
{
//Do Something
}}
Frustrating thing however is that your MovieClip is now only clickable on its graphics. So say it has some text and some lines, it will be only clickable when the mouse is exactly hovering above character-pixels or precisely above the line-pixels.
I found a real easy trick that makes a user defined region clickable. Dynamically draw a invisible shape(!) defining the region you want to be clickable using the Flash drawing API. This invisible drawing is impossible in the authoring tool. I tried it, but invisible graphics collapse/disappear.
I defined a function handling the onLoadInit event to draw my “click”-region.
public function onLoadInit()
{
drawClickableRegion();
}
private function drawClickableRegion()
{beginFill(0xFFFFFF, 0);
moveTo(-2.5, -5);
lineStyle(0, 0xFFFFFF, 0);
lineTo(-2.5,5);
lineTo(35,5);
lineTo(35,-5);
lineTo(-2.5,-5);
endFill();
}
As you can see, my code draws a box between -2.5,-5 and 35,5. I use fill- and line-color 0xFFFFFF with an alpha 0. You can use any arbitrarily chosen color but make sure you set the alpha to 0 to make your shape invisible. From now onwards your dynamically created MovieClip is a button. Remember to redraw this region whenever you use the clear() function on this MovieClip elsewhere in your code.
Flash Actionscript string[] array
August 22, 2006
Someone found my blog searching for “flash actionscript string[] array”.
I think this person is looking for a way to build a string array in ActionScript. That’s easy.
The ActionScript language reference explains the Array constructor like this:
public Array([value:Object])
Let’s you create an array. You can use the constructor to create different types of arrays: an
empty array, an array with a specific length but whose elements have undefined values, or an
array whose elements have specific values.
- Usage 1: If you don’t specify any parameters, an array with a length of 0 is created.
- Usage 2: If you specify only a length, an array is created with length number of elements. The value of each element is set to undefined.
- Usage 3: If you use the element parameters to specify values, an array is created with specific values.
Parameters
value:Object [optional] – Either:
- An integer that specifies the number of elements in the array.
- A list of two or more arbitrary values. The values can be of type Boolean, Number, String,Object, or Array. The first element in an array always has an index or position of 0.
So here are two examples of how you could go about creating a String array in Flash
var str_example_array:Array = new Array(“Belinda”, “Gina”, “Kathy”, “Charlotte”,”Jane”);
Or
var str_example_array:Array = new Array();
str_example_array[0] = “Belinda”;
str_example_array[1] = “Gina”;
str_example_array[2] = “Kathy”;
str_example_array[3] = “Charlotte”;
str_example_array[4] = “Jane”;
I hope that this is of help. If you have questions, ask them!
Asynchronous calls from Flash
August 21, 2006
In ActionScript it’s possible to ask a fileserver or webserver to go and fetch something for you while ActionScript continues doing work. You can use the LoadVars class for that purpose.
This LoadVars mechanism works as follows
- You define a Event-Handler that implements a function that handles the “onLoad” event
- You create a LoadVars object that’s going to receive the reply to your request.
- You add the Event-Handler to it’s listeners array.
- You create a LoadVars object that’s gonna carry the request.
- You optionally load the LoadVars request object with parameters
- You send the request
- Your ActionScript continues while the LoadVars object is going to the server
- When the receiving LoadVars object is filled with the reply to your request, the onLoad function fires and handles the servers answer.
I encountered a reocurring problem which has a real simple solution that I want to share with you.
The Problem.
There are times when the reply’s to a request are of no interest anymore when they reach your client code. For example consider your browsing through text/picture/sound -items, when you decide to stop waiting for an item (for example because the item takes too long to load), you don’t want it to pop-up later and interrupt the new stuff your doing.
Let’s state, in slightly more formal form, the characteristics of the problem;
You receive a reply to a request that belongs to a possible series of requests to which the rule applies that only the answer to the last request is interesting. How to filter out the noise?
The Solution.
I encountered this problem in many forms and this is my general solution pattern to it. The requests usually all come from the same class. In this class I keep a variable that at all times hold an encoding of the last initiated request. An encoded request variable is inserted in the request LoadVars and returned by the server. Anytime a reply to a request reaches my code I can check whether it’s a reply to the last request (by comparing the received request-encoding with the stored last-request-encoding) to determine whether it’s of interest to me. Encoding the request sounds harder then it is. You could for example, store the id of an item you requested.
Findability and Linkability with Flash
August 21, 2006
As promised, I will give you a short summary of how I implemented linkability and findability for a Flash blog I’m building.
Linkability and findability are obviously strongly related. For findability it helps a lot when people are able to link to your blog and even better if they’re able to link to specific content in your blog. But there’s more to findability; being indexed by search engines (important!) for example depends for a big part on being readable for the search engine web-crawlers.
Linkability.
Okay linkability first. In HTML blogs, links to specific blog entries usually aren’t directing to physical files, but instead contain instructions for the server to generate a HTML page with the requested content. For as far as I know, it’s not practical to try to generate Flash movies on request. But what we can do instead is create a HTML page that embeds a Flash Movie and contains some parameters that can be used by the Flash Movie to request the content that the user intended to see.
In my case this is my implementation. I supplied links of the form: http://mydomain/?blog_item=1 (1 or any other number)
and on the server side there is a php script that goes something like this:
<?php
$flashparameters = “”;
if(isset ($_REQUEST['blog_item'])) $flashparameters = “?blog_item=”.$_REQUEST['blog_item'];
?><object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase = “https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0″ width=”1024″ height=”768″ id=”mymovie” align=”middle”>
<param name=”allowScriptAccess” value=”sameDomain” />
<param name=”movie” value=”mymovie.swf<?=$flashparameters?>” /><param name=”menu” value=”false” /><param name=”quality” value=”best” /><param name=”bgcolor” value=”#ffffff” /><embed src=”mymovie.swf<?=$flashparameters?>” menu=”false” quality=”best” bgcolor=”#ffffff” width=”1024″ height=”768″ name=”mymovie” align=”middle” allowScriptAccess=”sameDomain” type=”application/x-shockwave-flash” pluginspage=”https://www.macromedia.com/go/getflashplayer” />
</object>
The result of embedding the Flash Movie using “mymovie.swf?blog_item=1” in the HTML page is that the variable blog_item is created in “_root” scope and contains value 1. The Flash Movie contains actionscript that checks whether _root.blog_item is initialized and bases it actions on that information. In my case it goes something like this:
_root.attachMovie(“com.mydomain.website.Blog”,”blog”,_root.getNextHighestDepth());
if(_root.blog_item != undefined) _root.blog.openBlogEntry(_root.blog_item);
else _root.blog.init();
Findability.
Search engines are bad at crawling the content of Flash Movies. There is not much you can do about that. But now that we have implemented linkability we can present the website – that used to be one static page (in the eyes of a search engine that can’t look into Flash Movies) – as multiple pages. Using RSS we can expose specific data on each link. In my case I used php server side scripting to generate a RSS feed that looks like this.
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<rss version=”2.0″>
<channel>
<title>My Domain Blog</title>
<link>http://www.mydomain.net</link>
<description>Letting you know what’s going on at My Domain</description>
<item>
<title>Building MyDomain.net</title>
<link>http://www.mydomain.net/blog_html.php?blog_item=28</link>
<pubDate>Thu, 10 Aug 2006 00:00:00 +0000</pubDate>
<description>blablablabla<a href=”http://www.mydomain.net/?blog_item=28″>View this story in Flash.</a></description>
<language>en</language>
<author>me@mydomain.net</author>
</item>
……..
</channel>
</rss>
I filled the <description> with the text content of the Flash blog entry. The <link> is a link to a HTML page containing again the text content of the blog entry. Both the description and the HTML page contain a link to the Flash version of the blog entry. Using this approach instead of directly embedding the Flash Movie prevents that subscribers to your feed stare at a blank page in aggregators that collapse your Flash Movie because they don’t know how to handle it. Everyone knows how to handle hyperlinks, you open them in the systems browser!
In my case I used actionscript hyperlinks in my texts that only make sense in the context of the Flash. For example: <a href=”asfunction:openBlogEntry,6″>Blog entry 6</a>. To exclude them from your HTML/RSS there is a PHP function that makes this a piece of cake: strip_tags. Saves you the trouble of making up your own regular expressions. I used it like this:
$description = strip_tags($description, ‘<b><i><u>’);
So style tags are preserved while hyperlinks are removed!
Blogging in Flash
August 20, 2006
What if you wanted to put a Blog inside a Flash website. Say your an artist that wants a rich flashy interactive website, with a lot of bells and whistles, and amidst of all that you want a blog. Well, is blogging in Flash that much different from blogging in HTML? I think it is. If been trying to do it and here are the first results from that endeavour.
First to recap what blogging is, this excerpt from “Naked Conversations“; (book by Robert Scoble and Shel Israel).
Bloggings’s Six Pillars: There are six key differences between blogging and any other communications channel. You can find any of them elsewhere. These are the Six Pillars of Blogging:
- Publishable.
Anyone can publish a blog.You can do it cheaply and post often. Each posting is instantly available worldwide.- Findable.
Through search engines, people will find blogs by subject, by author, or both. The more you post, the more findable you become.- Social.
The blogosphere is one big conversation. Interesting topical conversations move from site to site, linking to each other. Through blogs, people with shared interests build relationships unrestricted by geographic borders.- Viral.
Information often spreads faster through blogs than via a newsservice. No form of viral marketing matches the speed and efficiency of a blog.- Syndicatable.
By clicking on an icon, you can get free “home delivery” of RSS- enabled blogs into your e-mail software. RSS lets you know when a blog you subscribe to is updated, saving you search time. This process is considerably more efficient than the last- generation method of visiting one page of one web site at a time looking for changes.- Linkable.
Because each blog can link to all others, every blogger has access to the tens of millions of people who visit the blogosphere every day.
Now adhering to pillar 1-Publishable, 3-Social, 4-Viral and 5-Syndicatable will pose no different technical difficulties in Flash then in there counterpart HTML. But to be able to incorporate Findability and Linkability I see some challenges in using Flash.
Findability with Flash Blog.
Optimizing your website for Flash is tough. Search engines are not (yet) good at crawling them. And it’s my understanding, but I could be wrong on this one, that those search engines that are able to read text inside Flash movies can only read what is placed there at authoring time and not the dynamically at run-time imported texts. And your blog would of course consist of dynamic content.
So how to expose your unexposed blog content to search engines. Well you might think your RSS feed could be used for this purpose. Let’s see how you would use your RSS feed for that purpose. I take RSS 2.0 as an example. RSS is very simple and very strict. This could be the RSS of your Flash site;
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<rss version=”2.0″>
<channel>
<title>My Flash Blog</title>
<link>http://myflashsite/blog</link>
<description>A description of my Flash Blog</description><item>
<title>My Second Flash Blog post</title>
<link>http://myflashsite/blog/2</link>
<description>A description of my Second Flash Blog post</description>
</item>
<item>
<title>My First Flash Blog post</title>
<link>http://myflashsite/blog/1</link>
<description>A description of my First Flash Blog post</description>
</item></channel>
</rss>
O crap, the problem becomes obvious. RSS exposes only some meta-data of your blog entries. Like a title or a description, or a publish date, or an author. (See w3schools for a complete RSS reference.) But of course not the content, because if it would, RSS wouldn’t be Real Simple Syndication, it would be a building-websites-technology. A large benefit of you RSS to subscribers is that they’re able to detect (without visiting your real site) what content has been updated and to be able to judge whether it’s of interest to them before downloading it.
So how do we tackle the findability issue with Flash. The only solution I could come up with is to develop HTML and Flash versions of your blog in parallel. Use the HTML version to be index-able by the search engines and make a link available to the Flash version. I could not come up with any better. Please if your know of better ways let me know!
Linkability with Flash Blog.
Linkability with a Flash Blog is also far from trivial. In an HTML blog the URL’s linking to blog entries are either URL’s linking to existing distinct physical files or (most often) they are URL strings that need to be parsed by a server to generate the requested blog entry. For example URL’s like http://channel9.msdn.com/Showpost.aspx?postid=226369 and URL’s like http://on10.net/Blogs/TheShow/4960/. A lot of server side technologies have been developed to extract from URL’s the users intent and generate from that a HTML page with the users requested content embedded in it. Big problem with Flash is that it’s not dynamically created on the server-side. The best you can do is created a static Flash movie and have it dynamically request it ‘s contents from the server by using some parameters embedded in the HTML page surrounding the Flash movie. To make this work you need two mechanisms in place.
- Server side mechanism to parse URL and build from it a HTML page containing your Flash movie and the parameters that it needs to get your blog entry.
- Flash mechanism that uses the parameters to form a request to your server and get the requested blog entry.
Luckily this detour is invisible for your visitors. The technical implementation is doable. I haven’t implemented this yet, but when I have I will post a code example here.
Please if anyone has build a blog in Flash before, please let me know how you tackled the problems of findability and linkability. Thanks in advance!
Flash drawing API bezier
August 18, 2006
Yesterday someone visited my blog searching for “flash drawing api bezier”. I doubt whether this person found what he was looking for, because there is very little information on the Flash bézier functionality on my blog.
Okay let’s change that!
First here is a general introduction to Bézier curves.
In basic calculus courses, the type you get on high schools, you learn how to describe plane curves by giving y as a function of x [y = f(x)] or of course x as a function of y [x = f(y)] or by giving a relation between x and y that defines y implicitly as a function of x [f(x,y) = 0]. But there are more methods to describe curves. Bézier curves use a method called “curves defined by parametric equations”. X and y coordinates of the curve are given in terms of a third variable t called a parameter [x = f(t), y = g(t)]. There is a good explanation of the mathematics of Bézier curves on wikipedia, don’t get scared by all the math, wikipedia explains far more then you need to know for usage in Flash.
Bézier curves in Flash.
Flash supports the “simple” quadratic bézier curve. It’s a curve that has a begin-point, an end-point and a control-point. The begin-point is the point in which your curve starts. The endpoint is of course where your curve stops. And the control point is used as an influence on the curve, it sort of sucks the line in it’s direction.
The parametric equations that traces the curve is like this;
B(t) = (1-t)^2 * ‘begin-point‘ + 2t(1-t) * ‘control-point‘ + t^2 * ‘end-point‘ , t ∈ [0,1]
Using the ActionScript drawing API to draw a quadratic bézier curve
Here is how you use all these knowledge to draw a bezier curve with actionscript.
This code example creates an empty movieclip on the stage and draws a curve in it. Of course you can also draw on an already existing MovieClip or attach to the stage an MovieClip coming from the library and draw on that.
_root.createEmptyMovieClip(“curve_example”,_root.getNextHighestDepth());
_root.curve_example.clear();
//begin point 10,10
_root.curve_example.moveTo(10,10);
//control point 20,20 and endpoint 30,10
_root.curve_example.curveTo(20,20,30,10);
That’s your basic curve. With a little afford you can make something really nice out of a few curves. Here is an example I that I made with the drawing API. It’s 8 curves that change there anchor and control points, as well as their linestyle in time.
Flash Actionscript String Replace
August 14, 2006
Actionscript 2.0 has serious shortcomings with regard to String functions. Luckily I’ve not been the only-one frustrated by this, and lot’s of people have already done lot’s of work to overcome Macromedia’s shortcomings. Earlier I found this “String Functions Macromedia forgot“, and posted about how I made it in to a Toolkit instead of extending the String prototype. Today I wrote a function that is a small alteration of the String fullreplace function that might be very useful for you too.
What the fullreplace function does is too replace in a given String s occurrences of a sub-string matchwhat with a String replacewith. I was trying to use this function in the context of a text search functionality. In my Flash application I gave people the opportunity to search for a certain string. And have that string highlighted in the text results. Function fullreplace did not completely have the intended results.
For example;
When searching for “daan”, a search result “… Daan Roosegaarde …” would be displayed as; “… daan Roosegaarde …”. Of course I would have preferred this to be; “… Daan Roosegaarde …”
I called my function fullEmphasize. The function searches ignoring case, but replaces the matchwhat string with an emphasized version of the matchwhat that preserves the upper- and lowercases of the searchresult.
// used by fullEmphasize function, this function returns
// an array of the lowercase string split by the lowercase
// word we’re replacing
public static function rawfind(s:String ,match:String):Array
{
var sources = s.toLowerCase();
match = match.toLowerCase();
return sources.split(match);
}
// Emphasize all occurences of `matchwhat` with “<b>”+matchwhat+”</b>”
public static function fullEmphasize(s:String, matchwhat:String):String
{
var returnstring = “”;
var matches = rawfind(s,matchwhat); var atindex = 0;
var endat = matches.length – 1;for(var i=0; i<matches.length; i++)
{
var matchedword = matches[i]; returnstring += s.substr(atindex, matchedword.length);
if(i < endat)
{
atindex += matchedword.length;
returnstring += “<b>”+s.substr(atindex,matchwhat.length)+”</b>”;}
atindex += matchwhat.length;
}
return returnstring;
}
UPDATE March 7 2007:
Jack provided a better implementation for the rawfind function
[QOUTE from Jack's comment]
I like your code, but there is one small problem with the rawfind function. It will return an array of characters if the empty string is passed in as the match parameter (ECMA-262). Below is my fix for this problem as well as a variation of your fullEmphasize function which emphasizes matched strings by color( assuming an html enabled text ).// used by fullEmphasize function, this function returns
// an array of the lowercase string split by the lowercase
// word we’re replacing
public static function rawfind(s:String ,match:String):Array
{
if( match != “” )
{
var sources = s.toLowerCase();
match = match.toLowerCase();
return sources.split(match);
}
else // return unaltered string as array element 0
{
var rArray = new Array();
rArray.push(s);
return rArray;
}
}
[/QOUTE]
Another day, another fight with Flash
August 13, 2006
Today once again I was confronted with strange Flash behaviour. This time the struggle was about using CSS style on html text in a Flash TextField using an embedded font. I hope I help someone with writing down what I found out.
Okay the problem was this. When using an embedded font in combination with a TextField.StyleSheet, part of my html text disappeared. I solved this by specifying for each HTML tag the font to be used. This is part of what my CSS initialization looked like:
var globalCSS:TextField.StyleSheet = new TextField.StyleSheet();
globalCSS.parseCSS(“a:link {color: #1b5085; font-family: Frutiger55_Bold_Font; font-weight: bold; text-decoration: none; } a:hover {color: #1b5085; font-family: Frutiger55_Bold_Font; font-weight: bold; text-decoration: underline; } b { font-family: Frutiger55_Bold_Font; font-weight: bold; } i { font-family: Frutiger55_Font; } ul { font-family: Frutiger55_Font; } li { font-family: Frutiger55_Font; } .blogHeader { font-family: Frutiger55_Bold_Font; font-size: 14; } .blogDate { font-family: Frutiger55_Bold_Font; font-size: 10; }”);
The font names that I used for the “font-family” CSS property correspond to the library linkage identifier for “export for ActionScript”. (You can set this by right clicking on your embedded font in the library and checking the checkbox “export for ActionScript”.) As you see I included a separate ‘regular’ (Frutiger55_Font) and ‘bold’ (Frutiger55_Bold_Font) font. Just to display parts of the text bold and others not. This was necessary in my situation, but I’ve seen fonts that did not require this. Hope this is of some help to someone. It would have saved me a lot of frustration if I had found something similar!


