Flash notes

notes - undocumented features - coorections - etc
Mai, 2006

 
     
 

table of contents :
setInterval()
setTimeout()
Updating the Scrollpane Component
asfunction
Supported HTML tags
Javascript Fullscreen

 

doc links :
gravity.pdf
easing.pdf
elasticity.pdf

 
   
   

subject

 

comments

   
   
   

setInterval()

Note when using the syntax: setInterval(functionReference:Function, interval:Number):Number ; do not use quotation marks when referencing your function as you would for the other syntax

Example:

intervalId = setInterval(myFunction, 100);

function myFunction():Void{
trace("Interval trace");
clearInterval(intervalId);
};

   
   
   

setTimeout()

The setTimeout() and clearTimeout() global functions were inadvertently omitted from the documentation. The setTimeout() function allows you to create a one-time only timer. It is similar to the setInterval() function, except that setTimeout() will call the specified function once, while setInterval() calls the specified function repeatedly.

-------

function setTimeout (functionReference:Object, delay:Number, args:Object) : Number;

functionReference:Object -- The name of the function to execute. Do not include quotation marks or parentheses, and do not specify

delay:Number -- The delay, in milliseconds, until the function is executed.

args:Object -- Zero or more arguments, separated by commas, to be passed to the function.

Returns a Number that can be used as an argument to clearTimeout() to cancel the function call.

-------

function clearTimeout(id:Number) : Void;

id:Number -- The identification number of the setTimeout() call to cancel.

-------

Example using both setTimeout() and clearTimeout()

The following example uses setTimeout() to call a function named my_delayedFunction after a two second delay, and uses the return value to call clearTimeout() if the user presses the Spacebar. The example will output the string "two second delay" after two seconds has elapsed, unless the user presses the Spacebar before my_delayedFunction is called.

var my_timedProcess:Number = setTimeout(my_delayedFunction, 2000, "two second delay");

function my_delayedFunction (arg1) {
trace(arg1);
}

var escListener:Object = new Object();
escListener.onKeyDown = function() {
if (Key.isDown(Key.SPACE)) {
clearTimeout(my_timedProcess);
}
};
Key.addListener(escListener);

  • maciekw said on Sep 15, 2005 at 8:52 AM :
    unfortunately using setTimeout in external classes is not so easy, because of lack of intrinsic function declaration in toplevel.as

You can do it two ways:
1. call
_global.setTimeout()
_global.clearInterval()

instead
2. edit toplevel.as
(C:\Program Files\Macromedia\Flash 8\en\First Run\Classes on my computer)
and add two lines
intrinsic function clearTimeout(id:Number):Void;
intrinsic function setTimeout():Number;

before #endinitclip directive
maciekw said on Sep 16, 2005 at 2:47 AM :
also use setTimeout in external classes in the second form (exactly as setInterval)

setTimeout(scope:Object, funcName:String, miliSec:Number);

  • paulneave said on Sep 16, 2005 at 7:20 AM :
    Is there any chance setTimeout could be added to the Flash 8 Help docs - it's currently omitted by the looks of it (searching for 'timeout' only brings up the Camera object at the moment).Thanks.

  • dwabyick said on Nov 22, 2005 at 12:06 PM :
    It seems like this API is slightly flawed, as setTimeout doesn't allow you to specify a "this" object, like the second form of setInterval For example, setInterval( this, "myfunc", 1000);

This can be worked around by passing "this" in the arguments, I guess. But still its a bummer.

  • Southern Sun said on Feb 25, 2006 at 7:15 PM :
    This si the AS3 documentation of SetTimeout:

http://livedocs.macromedia.com/labs/1/flex/langref/flash/util/package.html#setTimeout()

  • Yup, you heard it here first. In Flash 8 actionscript you can tell the player to call a function just once after a specified interval. This means that you dont have to use setInterval anymore to call a function just once. For example the following code calls the openWebsite function after 1 second (1000 milli-seconds) and passes it a url. The openWebsite function then opens that url in a new browser window.

    function openWebsite(url:String)  {
    getURL(url,'_blank')
    }  
    website='http://www.flashguru.co.uk'  setTimeout(openWebsite,1000,website)  

    And of course you can use the following syntax aswell:

    function openWebsite(url:String)  {      
    getURL(url,'_blank')  
    }  
    website='http://www.flashguru.co.uk'  setTimeout(this,'openWebsite',1000,website)  

    Yet another one of those small features that make our lifes as Flash Developers just that little bit easier

    Note: That to use the setTimeout function is Actionscript 2 classes, you will need to use array notation to avoid compiler errors as this function was left out of the intrinsic class definition files:

    //call the showPopup function once after a second (1000 ms)  
    _global['setTimeout'](this,'showPopup',1000);  


   
   
   

Updating the Scrollpane Component

add this code after changing the size of the SP's content :
(SP= Scrollpane object Path)

SP.content.initMenu();

SP.onComplete();

   
   
   

asfunction

calling functions with a href anchor tag in flash text

When embedding links in html text in flash href tags not only can call extern web pages, but it can activate some actionscript to.
This feature allows blocks of text formatted in HTML to impact the flow of a Flash site or application.

To achieve this we got to use the asfunction, the asfunction is available in both flash 5 and Flash MX
To invoke actions we use the HTML anchor tag. I’ts not possible to call actionscript code directly from the tag, instead you call ActionScript functions. The format for this in flash is:

<a HREF="asfunction:myFunction">call function</a>

Macromedia flash allows to pass one parameter to a function using the href attribute of the HTML anchor tag. Any additional parameters will be used as additional calls to the function. The format for calling a function with parameter in flash is:

<a HREF="asfunction:myFunction,myParameter">call function</a>

Note: you can pass ONE parameter and only one.

   
   
   

Supported HTML tags

This section lists the built-in HTML tags supported by Flash Player. You can also
create new styles and tags using CSS; see Formatting text with Cascading Style
Sheets.

Anchor tag (<a>)


The <a> tag creates a hypertext link and supports the following attributes:

  • href Specifies the URL of the page to load in the browser. The URL can be either
    absolute or relative to the location of the SWF file that is loading the page.
    An example of an absolute reference to a URL is http://www.macromedia.com; an
    example of a relative reference is /index.html.

  • target Specifies the name of the target window where you load the page. Options
    include _self, _blank, _parent and _top. The _self option specifies the current
    frame in the current window, _blank specifies a new window, _parent specifies
    the parent of the current frame, and _top specifies the top-level frame in the
    current window.
    For example, the following HTML code creates the link "Go home," which
    opens www.macromedia.com in a new browser window:

urlText_txt.htmlText = "<a href=’http://www.macromedia.com’ target=’_blank’>Go
home</a>";

You can use the special asfunction protocol to cause the link to execute an
ActionScript function in a SWF file instead of opening a URL. For more information
on the asfunction protocol, see asfunction in Flash ActionScript Language Reference.

You can also define a:link, a:hover, and a:active styles for anchor tags by
using style sheets. See Styling built-in HTML tags.

Bold tag (<b>)


The <b> tag renders text as bold, as shown in the following example:

text3_txt.htmlText = "He was <b>ready</b> to leave!";

A bold typeface must be available for the font used to display the text.

Break tag (<br>)


The <br> tag creates a line break in the text field. In the following
example, the line breaks between sentences:

text1_txt.htmlText = "The boy put on his coat. <br>His coat was
<font color=’#FF0033′>red</font> plaid.";

The closing </br> tag is optional, but it is good practice to include
it.

Font tag (<font>)


The <font> tag specifies a font or list of fonts to display the text. The font tag supports the following attributes:

  • color Only hexadecimal color (#FFFFFF) values are supported. For example, the
    following HTML code creates red text:
    myText_txt.htmlText = "<font color=’#FF0000′>This is red text</font>";

  • face Specifies the name of the font to use. As shown in the following example,
    you can specify a list of comma-delimited font names, in which case Flash Player
    selects the first available font:
    myText_txt.htmlText = "<font face=’Times, Times New Roman’>
    Displays as either Times or Times New Roman…</font>";

If the specified font is not installed on the user’s computer system or isn’t
embedded in the SWF file, Flash Player selects a substitute font.

  • size Specifies the size of the font, in pixels, as shown in the following example:

myText_txt.htmlText = "<font size=’24′ color=’#0000FF’>This is blue,24-point text</font>";

You can also use relative point sizes instead of a pixel size, such as +2 or -4.

Image tag (<img>)

The <img> tag lets you embed external JPEG files, SWF files, and movie
clips inside text fields and TextArea component instances. Text automatically
flows around images you embed in text fields or components. This tag is supported
only in dynamic and input text fields that are multiline and wrap their text.

To create a multiline text field with word wrapping, do one of the following:

In the Flash authoring environment, select a text field on the Stage and then,
in the Property inspector, select Multiline from the Text Type menu.

For a text field created at runtime with MovieClip.createTextField(), set the
new text field instance’s TextField.multiline and TextField.wordWrap properties
to true.

The <img> tag has one required attribute, src, which specifies the path
to a JPEG file, a SWF file, or the linkage identifier of a movie clip symbol
in the library. All other attributes are optional.

The <img> tags supports the following attributes:

  • src Specifies the URL to a JPEG or SWF file, or the linkage identifier for
    a movie clip symbol in the library. This attribute is required; all other attributes
    are optional. External files (JPEG and SWF files) do not show until they have
    downloaded completely.
    Note: Flash Player supports non-progressive JPEG files, but does not support
    progressive JPEG files.

  • id Specifies the name for the movie clip instance (created by Flash Player)
    that contains the embedded JPEG file, SWF file, or movie clip. This is useful
    if you want to control the embedded content with ActionScript.
    width The width of the image, SWF file, or movie clip being inserted, in pixels.

  • height The height of the image, SWF file, or movie clip being inserted, in pixels.

  • align Specifies the horizontal alignment of the embedded image within the text
    field. Valid value are left and right. The default value is left.

  • hspace Specifies the amount of horizontal space that surrounds the image where
    no text appears. The default value is 8.

  • vspace Specifies the amount of vertical space that surrounds the image where
    no text appears. The default value is 8.


For more information and examples of using the <img> tag, see Embedding
images, SWF files, and movie clips in text fields.

Italic tag (<i>)

The <i> tag displays the tagged text in italics, as shown in the following
code:

That is very <i>interesting</i>.

This code example would render as follows:
That is very interesting.
An italic typeface must be available for the font used.

List item tag (<li>)


The <li> tag places a bullet in front of the text that it encloses, as
shown in the following code:

Grocery list:
<li>Apples</li>
<li>Oranges</li>
<li>Lemons</li>

This code example would render as follows:

Grocery list:

Apples
Oranges
Lemons


Note: Ordered and unordered lists (<ol> and <ul> tags) are not recognized
by Flash Player, so they do not modify how your list is rendered. All list items
use bullets.

Paragraph tag (<p>)


The <p> tag creates a new paragraph. It supports the following attributes:

  • align Specifies alignment of text within the paragraph; valid values are left,
    right, and center.

  • class Specifies a CSS style class defined by an TextField.StyleSheet object.
    (For more information, see Using style classes.)
    The following example uses the align attribute to align text on the right side
    of a text field.

myText_txt.htmlText = "<p align=’right’>This text is aligned on the right side of the text field</p>";

The following example uses the class attribute to assign a text style class
to a <p> tag:

var myStyleSheet = new TextField.StyleSheet();
myStyleSheet.setStyle("body", {color:’#99CCFF’, fontSize:’18′});
this.createTextField("test", 10, 0, 0, 300, 100);
test.styleSheet = myStyleSheet;
test.htmlText = "<p class=’body’>This is some body-styled text.</p>.";

Span tag (<span>)

The <span> tag is available only for use with CSS text styles. It supports
the following attribute:

  • class Specifies a CSS style class defined by an TextField.StyleSheet object.
    For more information on creating text style classes, see Using style classes.

Text format tag (<textformat>)

The <textformat> tag lets you use a subset of paragraph formatting properties
of the TextFormat class within HTML text fields, including line leading, indentation,
margins, and tab stops. You can combine <textformat> tags with the built-in
HTML tags.

The <textformat> tag has the following attributes:

  • blockindent Specifies the block indentation in points; corresponds to TextFormat.blockIndent.
    (See TextFormat.blockIndent in Flash ActionScript Language Reference.)

  • indent Specifies the indentation from the left margin to the first character
    in the paragraph; corresponds to TextFormat.indent. (See TextFormat.indent in
    Flash ActionScript Language Reference.)

  • leading Specifies the amount of leading (vertical space) between lines; corresponds
    to TextFormat.leading. (See TextFormat.leading in Flash ActionScript Language
    Reference.)

  • leftmargin Specifies the left margin of the paragraph, in points; corresponds
    to TextFormat.leftMargin. (See TextFormat.leftMargin in Flash ActionScript Language
    Reference.)

  • rightmargin Specifies the right margin of the paragraph, in points; corresponds
    to TextFormat.rightMargin. (See TextFormat.rightMargin in Flash ActionScript
    Language Reference.)

  • tabstops Specifies custom tab stops as an array of non-negative integers; corresponds
    to TextFormat.tabStops. (See TextFormat.tabStops in Flash ActionScript Language
    Reference.)

To create a formatted table of data using tab stops:
Using the Text tool, create a dynamic text field that’s approximately 300 pixels
wide and 100 pixels high.
In the Property inspector, name the instance table_txt, select Multiline from
the Line Type pop-up menu, and select the Render Text as HTML option.
In the Timeline, select the first frame on Layer 1.
Open the Actions panel (Window > Development Panels > Actions), and enter
the following code in the Actions panel:

//Creates column headers, formatted in bold, separated by tabs
var rowHeaders = "<b>Name\tAge\tDepartment</b>";

//Creates rows with data
var row_1 = "Tim\t32\tFinance";
var row_2 = "Edwin\t46\tMarketing";

//Sets two tabstops, to 50 and 100 points
table_txt.htmlText = "<textformat tabstops=’[50,100]’>";
table_txt.htmlText += rowHeaders;
table_txt.htmlText += row_1;
table_txt.htmlText += row_2 ;
table_txt.htmlText += "</textformat>";

The use of the tab character escape sequence (\t) adds tabs between each column
in the table.

Select Control > Test Movie to view the formatted table.

Underline tag (<u>)

The <u> tag underlines the tagged text, as shown in the following code:

This is <u>underlined</u> text

   
         

Javascript Fullscreen

Html , not flash

paste into head :

<script Language="javascript">self.moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight);</script>

result is resize to max width and height onLOAD