blog.Ring.idv.tw

變數範圍-一個獨立於Flash Player中的物件「_global」(全域變數)

變數範圍-一個獨立於Flash Player中的物件「_global」(全域變數)

根據「ActionScript 2.0 Language Reference」在「_global」的描述中,我們可以知道它是在「Flash Player 6」之後出來的產物,這裡我們就來談談「全域變數」~

一個獨立於Flash Player中的物件「_global」

通常設定一個「全域變數」的變數或是函數的話,基本上用法大致如下:

程式一

_global.foo = 10;
_global.func = function()
{
	trace(this.foo);
}
func();

結果:

10

在上述程式的「func」匿名函數中,我們使用「this」來代表我們將存取此「_global」自身的一些屬性,而從結果中我們的確將「foo」屬性利用「trace」函數將它的值顯示在「Output Panel」中,接著我們再來看另一個例子:

trace(typeof(_global));

結果:

object

在「Output Panel」你會發現結果顯示出「_global」居然是一個物件?的確!Flash Player所設計的「全域變數」的確就是仰賴「_global」物件來加以達成的!

倘若我們將程式一利用「偵錯模式(Ctrl+Shift+Enter)」來看的話,你會發現下圖的證據所在:

2007-06-30 22:23:53

Leave a Comment

Copyright (C) Ching-Shen Chen. All rights reserved.

::: 搜尋 :::

::: 分類 :::

::: Ads :::

::: 最新文章 :::

::: 最新回應 :::

::: 訂閱 :::

Atom feed
Atom Comment