Jiagao.net topleft
Welcome to jiagao.net
[认识自己]
Jiagao.net topright

My Projects

MacroMedia LiveDocs

FLASH NEWS

FLASH RESOURCE

MY LINKS

本站搜索

Google AdSense

组件开发中事件处理的三种方法

《Three approaches to component event handling》
作者:Bob Donderwinkel

1、Using a fully qualified path
2、Changing the scope of the event handler with mx.utils.Delegate
3、Using an event listener model with mx.events.EventDispatcher

HTML版 | PDF版
评论 - 2005年01月14日, 星期五 15:37:57

Flash中DrawingAPI的使用

《Dynamic Drawing Using ActionScript》,josh的一篇教程,比较全面的介绍了使用ActionScript DrawingAPI绘图。
评论 - 2005年01月14日, 星期五 15:23:37

在Flash MX 2004中使用Tween和Transition类

Flash开发者中心(Flash Developer Center)中的一篇新文档《Using the Tween and Transition Classes in Flash MX 2004》,比较详尽的介绍了Tween、Transition的使用。这也是Macromedia官方的Tween和Transition类使用说明,估计8ball会把这两个类写进文档了吧。
评论 - 2005年01月05日, 星期三 09:36:28

[web标准]注意URL中的“&”

今日在调试网页的时候发现URL中的"&"应该替换为"&"
如:
<a href="foo.cgi?chapter=1&section=2">...</a>
上面的HTML代码在XHTML中校验无法通过的,应改为
<a href="foo.cgi?chapter=1&amp;section=2">...</a>

原文见这里
评论 - 2004年12月30日, 星期四 16:20:34

在SWF中获取HTML网页参数

本教程主要介绍HTML网页如何取得形如test.html?foo=mytest的foo参数,以及在HTML网页中如何向swf传递参数。

一、在HTML网页中使用js获取参数。
我们知道HTML页面是在客户端执行的,这样要获取参数必须使用客户端脚本(如JavaScript),在这点上不同于服务器端脚本获取参数方式。
下面的这段js代码获取HTML网页形如"test.html?foo=mytest&program=flash" "?"后所有参数。
<script language=javascript>
<!--
var hrefstr,pos,parastr;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?");
parastr = hrefstr.substring(pos+1);
if (pos>0){
document.write("所有参数:"+parastr);
} else {
document.write("无参数");
}
//-->
</script>


下面的这段js代码则可以更加细化获取HTML网页某一参数
<script language=javascript>
<!--
function getparastr(strname) {
var hrefstr,pos,parastr,para,tempstr;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?")
parastr = hrefstr.substring(pos+1);

para = parastr.split("&");
tempstr="";
for(i=0;i<para.length;i++)
{
 tempstr = para[i];
 pos = tempstr.indexOf("=");
 if(tempstr.substring(0,pos) == strname) {
  return tempstr.substring(pos+1);
 }
}
return null;
}
// 获取program参数
var programstr = getparastr("program");
document.write(programstr);
//-->
</script>


二、在HTML网页中向swf传递参数。
方法一:在网页中使用js,SetVariable设置flashobject中的变量,代码如:
// "HtmlToSwf"为网页中的flashobject ID
HtmlToSwf.SetVariable("_root.info_str","Happy Newyear");

方法二:路径参数,如test.swf?foo=happy2005
方法三:使用FlashVars,以下主要介绍FlashVars的用法。使用FlashVars后嵌入HTML的flashobject代码如下:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400" id="FlashVars" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="FlashVars.swf" />
<param name="FlashVars" value="foo=happy2005&program=flash&language=简体中文-中国" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="FlashVars.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="FlashVars" align="middle" allowScriptAccess="sameDomain" FlashVars="foo=happy2005&program=flash&language=简体中文-中国" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />


通过上面的代码,在SWF(FlashVars.swf)中就可以直接获取foo、program、language变量数据。FlashVars.fla获取FlashVars参数的代码如下:
// 创建三个文本字段
_root.createTextField("foo_txt",1,0,0,16,16);
_root.createTextField("program_txt",2,0,32,16,16);
_root.createTextField("language_txt",3,0,64,16,16);
foo_txt.autoSize = true;
foo_txt.border = true;
program_txt.autoSize = true;
program_txt.border = true;
language_txt.autoSize = true;
language_txt.border = true;
// 获取FlashVars变量
foo_txt.text = "HTML中的foo参数:"+foo;
program_txt.text = "HTML中的program参数:"+program;
language_txt.text = "HTML中的language参数:"+language;


三、两者的有效结合。
在HTML网页中使用js获取参数,然后将获取的参数作为FlashVars写入flashobject传递给swf。代码如下:
<script language=javascript>
<!--
function writeflashobject(parastr) {
document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"550\" height=\"400\" id=\"FlashVars\" align=\"middle\"\>\n");
document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" /\>\n");
document.write("<param name=\"movie\" value=\"FlashVars.swf\" /\>\n");
document.write("<param name=\"FlashVars\" value=\""+ parastr +"\" /\>\n");
document.write("<param name=\"quality\" value=\"high\" /\>\n");
document.write("<param name=\"bgcolor\" value=\"#ffffff\" /\>\n");
document.write("<embed src=\"FlashVars.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"550\" height=\"400\" name=\"FlashVars\" align=\"middle\" allowScriptAccess=\"sameDomain\" FlashVars=\""+ parastr +"\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /\>");
document.write("</object\>");
}
function getparastr() {
var hrefstr,pos,parastr,para,tempstr1;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?")
parastr = hrefstr.substring(pos+1);
return parastr;
}
var parastr = getparastr();
writeflashobject(parastr);
//-->
</script>


四、附:最终效果源码下载
评论 - 2004年12月30日, 星期四 11:52:36

MultiMovieLoader V2.0发布及源码下载

岁末将至,既定任务基本达成。利用一点空闲时间,重写了MultiMovieLoader,现发布,并附源码。权当元旦、春节送大家的一点薄礼!

前往MultiMovieLoader
评论 - 2004年12月29日, 星期三 00:48:02

Flash影片到底能有多大

How big can a Flash movie be? MM12月23日更新的Flash TechNote,主要阐述了Flash的上限方面问题,如其支持的最多元件数、最多层数、最大文件大小、ActionScript脚本处理能力等。文章所阐述的方法与观点及提供的讯息值得参考,比较喜欢里面的一句话:
The possibilities are endless, but memory is not.
评论 - 2004年12月26日, 星期日 18:08:13

让Flash播放器只运行一个实例

希望你的swf或者Flash Projector文件同时只能运行一个实例么?Abdul Qabiz使用LocalConnection对象实现了该功能,通过LocalConnection.connect()判断客户机上运行的进程是否已使用connectionName参数,如已使用则通过fscommand("quit");关闭播放器。代码如下:
//——————————————————// 
var _lc:LocalConnection = new LocalConnection();
if(!_lc.connect("myapp")) {
//You can handle this anyway you want, I am here just closing the projector.
fscommand("quit"); }
//——————————————————//


via IndiaMMUG
评论 - 2004年10月21日, 星期四 20:13:56

[V2组件]labelFunction和iconFunction函数的使用

iconFunction:指定一个函数,该函数用于确定每行将使用哪个图标来显示其项目。此函数会接收参数item(该参数指示所呈现的项目),并且必须返回一个表示图标元件标识符的字符串。
V2中Button、List、Tree、Menu组件可使用该函数。用于处理数据显示项目图标。使用时必须定义该函数,即:
myComponent.iconFunction = function(itemObj) { 
   return itemObj.iconSymbolIdentifierName;
}


labelFunction:格式化显示组件的标签文本中的内容。
众多V2组件都可使用该函数。使用时必须定义该函数,即:
myComponent.labelFunction = function(itemObj) { 
   return itemObj.labelString;
}


下面通过例子介绍labelFunction、iconFunction的用法,简单的翻译了Ted的文章:
1、从组件面板中拖放一Tree组件到舞台,定义实例名称为:“myTree”
2、在关键帧上加上如下Action,用于载入XML文档,作为“myTree”组件的dataProvider。
dx = new XML(); 
dx.ignoreWhite = true;
dx.load("http://www.powersdk.com/sample/treedata.xml?"+Math.random()*10000);
dx.onLoad = function(){
   myTree.dataProvider = this.firstChild;
}

3、继续上面的Action,为“myTree”组件实例创建上面我们介绍的两个函数,这两个函数用于呈现myTree组件中的项目标签及图表。
// 返回作为tree组件项目的图标的影片剪辑的链接标识。
myTree.iconFunction = function(node){
   return node.attributes.icon;
}
// 返回“myTree”组件的项目标签内容。
myTree.labelFunction = function(node){
   if(node.attributes.title == undefined){
       return node.attributes.name + " (Division)";
   }else{
       return node.attributes.name + " (" + node.attributes.title + ")";
   }
}

4、完工,测试。

相关链接:
下载源码
Ted的原文以及效果预览
评论 - 2004年10月08日, 星期五 21:25:24

函数定时执行

Dimitrios扩展了的Function类,版本AS1,代码如下:
// Function callAfter
// by Dimitrios Bendilas (d.bendilas@zefxis.gr)
Function.prototype.callAfter = function(_lag:Number, _parameters:Array) {
  var sTime = getTimer();
  var _function = this;
  var timer = setInterval(function () {
     if (getTimer()-sTime>=_lag) {
         _function.apply(null, _parameters);
         clearInterval(timer);
     }
  }, 50, this);
};
用法:
function traceData(name:String, age:Number) {
  trace(name+", age "+age);
}
traceData.callAfter(2000, ["John", 25]);// 2000 milliseconds
评论 - 2004年09月30日, 星期四 22:53:46