写程序的时候突然想到的方法,感觉简单又好用,一个实用函数,所以发出来,下面是这个函数:
/*
* author: fanflash(www.fanflash.cn)
* date: 2007-5-14
* info: 将文字转为点阵诸存
* -----Parameters-------
* dt: 要转换成字符串的字符
* w: 两点像素点之间的横轴间距
* h: 两点像素点之间的纵轴间距
* note: 如果想增加点的密度,可以把文本字号设置大些
*/
//检查参数的可用性
w = (w != undefined) ? w : 0;
h = (h != undefined) ? h : 0;
var t_txt:TextField = _root.createTextField("txtToPosTxt", _root.getNextHighestDepth(), -500, -500, 100, 100);
//设置文本
t_txt.autoSize = true;
t_txt.multiline = false;
t_txt.wordWrap = false;
t_txt.selectable = false;
t_txt.text = dt;
t_txt._visible = false;
//生成图片数据
var txtBmp:flash.display.BitmapData = new flash.display.BitmapData(t_txt._width, t_txt._height, false, 0xffffff);
txtBmp.draw(t_txt);
//创建文字数组
var t_arr:Array = new Array();
var pix:Number;
for (var y = 0; y<t_txt._height; y ) {
for (var x = 0; x<t_txt._width; x ) {
if (txtBmp.getPixel(x, y) != 0xffffff) {
t_arr.push({x:x x*w, y:y y*h});
}
}
}
//删除创建的文字
t_txt.removeTextField();
txtBmp.dispose();
return t_arr;
}
原理很简单,利用BITMAP类把黑色的点选出来,因为白色的是背景,所以只要是黑色的点,那么都是笔划和线条了.下面是一个用此函数的示例程序:
源程序:
System.useCodepage = true;
Stage.scaleMode = "noScale";
Stage.showMenu = false;
function main() {
var t:Array;
ok_btn.onPress = function() {
removeMC();
t = txtToPosArr(input_txt.text, 4, 4);
for (var i in t) {
createMC(t.x, t.y);
}
};
}
function txtToPosArr(dt:String, w:Number, h:Number):Array {
/*
* author: fanflash(www.fanflash.cn)
* date: 2007-5-14
* info: 将文字转为点阵诸存
* -----Parameters-------
* dt: 要转换成字符串的字符
* w: 两点像素点之间的横轴间距
* h: 两点像素点之间的纵轴间距
* note: 如果想增加点的密度,可以把文本字号设置大些
*/
//检查参数的可用性
w = (w != undefined) ? w : 0;
h = (h != undefined) ? h : 0;
var t_txt:TextField = _root.createTextField("txtToPosTxt", _root.getNextHighestDepth(), -500, -500, 100, 100);
//设置文本
t_txt.autoSize = true;
t_txt.multiline = false;
t_txt.wordWrap = false;
t_txt.selectable = false;
t_txt.text = dt;
t_txt._visible = false;
//生成图片数据
var txtBmp:flash.display.BitmapData = new flash.display.BitmapData(t_txt._width, t_txt._height, false, 0xffffff);
txtBmp.draw(t_txt);
//创建文字数组
var t_arr:Array = new Array();
var pix:Number;
for (var y = 0; y<t_txt._height; y ) {
for (var x = 0; x<t_txt._width; x ) {
if (txtBmp.getPixel(x, y) != 0xffffff) {
t_arr.push({x:x x*w, y:y y*h});
}
}
}
//删除创建的文字
t_txt.removeTextField();
txtBmp.dispose();
return t_arr;
}
import flash.filters.GlowFilter;
import mx.transitions.Tween;
import mx.transitions.easing.*;
function createMC(x:Number, y:Number) {
//点陈坐标偏移
x = 50;
y = 150;
//补间动画样式
var tweenFun:Function = Back.easeOut;
var d:Number = _root.getNextHighestDepth();
var _mc:MovieClip = _root.attachMovie("dot", "dot" d, d);
_mc.cacheAsBitmap = true;
//_mc.filters = [new GlowFilter(Math.round(Math.random()*0xffffff))];
_mc.filters = [new GlowFilter(0xffffff)];
_mc._x = Math.random()*Stage.width;
_mc._y = Math.random()*Stage.height;
var xt:Number = 1 Math.round(Math.random()*2);
var yt:Number = 1 Math.round(Math.random()*2);
new Tween(_mc, "_x", tweenFun, _mc._x, x, xt, true);
new Tween(_mc, "_y", tweenFun, _mc._y, y, yt, true);
}
function removeMC() {
for (var m in _root) {
if (_root[m]._name.substr(0, 3) == "dot") {
_root[m].removeMovieClip();
}
}
}
main();
源程序下载:点击这里下载源文件
private var authorStr:String
public function test(){
authorStr="fanflash"
}
public function set author(dt:String){
this.authorStr=dt;
}
public function get author():String{
return this.authorStr;
}
}
trace(t.author);
t.author="www.webjx.com"
trace(t.author);
trace(t.__get__author());
函数如下:
private function deleteComment(dt:String):String{
var mark:String="’"
var newStr:String;
//去除注释
var markID:Number=dt.lastIndexOf(mark,dt.length);
if(markID==-1){
newStr=dt; //没有注释
}else{
newStr=dt.slice(0,markID); //有注释
}
//去除空格
var len:Number=newStr.length;
var deleteID:Number=len //没有空白字符的位置
for(var i=len-1;i>=0;i--){
if(newStr.charAt(i)!=" "){
deleteID=i;
break; //跳出循环
}
}
return newStr.slice(0,deleteID 1);
}
比如有这样一个string,str的名字是aa:
----------------------------------------------------------------------------------
http://localhost/videoboard/saveimage/ '保存图片文件夹的地址
http://localhost/videobard/aspx/ '脚本文件文件平价的地址
------------------------------------------------------------------------------------
可以这样子使用上面那一个函数:
var txtArr:Array=dt.split("\n");
var len:Number=txtArr.length
for(var i=0;i<len;i ){
trace(this.deleteComment(txtArr[i]));
}
}
这个函数是来干什么呢?
我是写一个程序的配置文件,相着用XML太麻烦,数据冗余太大,最简单的就是把配置的变量写成一行一行的,又怕别人看不懂这个行变量的意思,所以在变量后面加上注释,但到程序里面肯定要把注释去掉,所以就有了上面的function.
function MoveTo(mcName, mcX, mcY, a) {
mcName.onEnterFrame = function() {
mcName._x = (mcX-mcName._x)/a;
mcName._y = (mcY-mcName._y)/a;
if (mcX == mcName._x && mcY == mcName._y) {
delete (mcName.onEnterFrame);
}
};
}
//-------函数调用-------
MoveTo("mc1", 100, 100, 2);
/*
相关参数说明:
mcName为指定要移动的对象的实例名称
mcX为要移动到指定点的X坐标
mcY为要移动到指定点的Y坐标
a为移动的加速度
调用方法:
MoveTo("mc1", 100, 100, 2)
mc1对象将以2的加速度移动到X轴100,Y轴100的位置
可以很方便的反复调用
感兴趣的还可以扩展相关功能:
比如对象的透明度,X,Y轴的缩放等。
syxu@3c800.com
*/
实现Flash动画文件全屏效果的三种方法
第一种方法:
不显示浏览器菜单栏、工具栏的全屏。这种全屏稍稍复杂,也与FLASH的设置无关,但要借助JavaScript来完成。方法是:在HTML文件中<head></head>间加入以下代码:
<script language="JavaScript">
<!--
window.open("nfd.swf","","fullscreen=1,menubar=no,width=100%,height=100%")
//-->
</script>
第二种方法:
也可以在SWF文件的第一帧Actions上的GETURL 命令上加上:
javascript:window.open("nfd.swf","","fullscreen=1,menubar=no,width=800,height=600")
这种全屏也是类似屏保,用ALT F4或设置按钮退出。把fullscreen设为=0,则只是不显示浏览器菜单栏、工具栏的全屏。
还有一个写法:
javascript:window.open("*.swf","","menubar=no,toolbar=no,location=no,status=no,fullscreen=yes")
第三种方法:
稍麻烦一些,需要两个网页,你可以建立个空白网页加上代码:
<html>
<script language="JavaScript">
window.open("*.htm","newwin","fullscreen=yes,status=no,location=no,
toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=no");
</script>
</html>
*.htm 你把他替换为你自己要全屏打开的网页就可以了
可以控制立方体的旋转:
cubeCenter = new point3d(0,0,0);
geom.addCube(cubeCenter, 80, 0xFFF2CC);
geom.addCube(cubeCenter, 20, 0xFFF2CC);
geom.addSolidCube(cubeCenter, 20, 0xC2B898, 30);
point1 = new point3d(-80,80,80);
point2 = new point3d(-80,80,-80);
point3 = new point3d(80,80,-80);
point4 = new point3d(80,80,80);
point5 = new point3d(-80,-80,80);
point6 = new point3d(-80,-80,-80);
point7 = new point3d(80,-80,-80);
point0 = new point3d(80,-80,80);
// attach a movie from the library and then add it
for (g=0; g<8; g ) {
attachMovie("glowball", "gb" g, depth );
mx3dInstance.addClip(eval("point" g), eval("gb" g));
}
源文件下载:点击这里下载源文件
在Flash8中,有个未公开的函数setTimeout,执行功能就是在设定的时间到了以后,调用一次设定的函数。 这样对于只需要调用一次的时间触发事件,我们再也不需要用 setInterval 函数配合 clearInterval 函数来处理了. 很好用,该函数属于未公开的函数的原因,很大可能是因为在flash 8.5中属于非推荐语法,所以隐藏了.
用法:
function openWebsite(url:String) {
getURL(url, "_blank");
}
website = "http://www.webjx.com/";
setTimeout(openWebsite, 1000, website);
stop();
或者
function openWebsite(url:String)
{
getURL(url,"_blank");
}
website='http://www.webjx.com';
setTimeout(this,'openWebsite',1000,website);
特别注意:
如果是是用AS2的类里面使用setTimeout函数,因为该函数属于未公开的函数,所以必须使用下面的方法才能避免编译出错
_global["setTimeout"](this,"openWebsite",1000,website);
无聊的时候就来把美女分割![由讨厌原创==>无聊+乱整]
import flash.display.BitmapData;
import flash.geom.Matrix;
/////////////////////////////////
var img_bmp:BitmapData = new BitmapData(mc._width, mc._height);
var txt_fmt:TextFormat = new TextFormat();
txt_fmt.color = 0xff00ff;
txt_fmt.size = 22;
txt_fmt.font = "华文新魏";
/////////////////////
for (var d:Number = 2; d>0; d--) {
this.createTextField("wh_txt" d, 9000 d, d*100, 20, 50, 26);
this["wh_txt" d].setNewTextFormat(txt_fmt);
this["wh_txt" d].border = true;
this["wh_txt" d].input = true;
this["wh_txt" d].type = "input";
this["wh_txt" d].maxChars = 1;
this["wh_txt" d].restrict("0-9");
this["wh_txt" d].background = true;
this["wh_txt" d].borderColor = 0xff9900;
this["wh_txt" d].backgroundColor = 0x33cccc;
}
Selection.setFocus("wh_txt1");
//////////////////
wh_txt1.onChanged = wh_txt2.onChanged=function () {
if (wh_txt1.text == "") {
Selection.setFocus("wh_txt1");
} else if (wh_txt2.text == "") {
Selection.setFocus("wh_txt2");
} else {
fenge_func(wh_txt1.text, wh_txt2.text);
}
};
////////////////////////
var xwpos:Number = 0;
var yhpos:Number = 0;
function fuwei_func() {
for (var d:Number = xwpos-1; d>=0; d--) {
for (var c:Number = yhpos-1; c>=0; c--) {
this["pic_mc" d c].removeMovieClip();
}
}
}
//////
function fenge_func(xw:Number, yh:Number) {
fuwei_func();
xwpos = xw;
yhpos = yh;
img_bmp.draw(mc, new Matrix());
var xy_array:Array = new Array();
var b_num:Number = new Number();
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
this.createEmptyMovieClip("pic_mc" d c, 200 d "" c);
this["pic_mc" d c].lineStyle(1, 0xfff000, 100);
this["pic_mc" d c].beginBitmapFill(img_bmp, new Matrix(), false);
this["pic_mc" d c].moveTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].endFill();
this["pic_mc" d c].obj = new Object();
this["pic_mc" d c].obj = this["pic_mc" d c].getBounds(_root);
this["pic_mc" d c].xpos = this["pic_mc" d c].obj.xMin;
this["pic_mc" d c].ypos = this["pic_mc" d c].obj.yMin;
////////////////
var xy2_array:Array = new Array();
xy2_array.push(this["pic_mc" d c].obj.xMin, this["pic_mc" d c].obj.yMin);
xy_array.push(xy2_array);
this["pic_mc" d c].id = d "" c;
//////////////////
this["pic_mc" d c].onPress = function() {
b_num = this.id;
this.swapDepths(this._parent.getNextHighestDepth());
this.startDrag();
};
}
}
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
num = Math.floor(Math.random()*xy_array.length);
this["pic_mc" d c]._x = xy_array[num][0]-this["pic_mc" d c].xpos;
this["pic_mc" d c]._y = xy_array[num][1]-this["pic_mc" d c].ypos;
xy_array.splice(num, 1);
}
}
//////////////////
onMouseUp = function () {
stopDrag();
if (this["pic_mc" b_num].hitTest(this["pic_mc" b_num].xpos this["pic_mc" b_num]._width/2, this["pic_mc" b_num].ypos this["pic_mc" b_num]._height/2)) {
this["pic_mc" b_num]._x = 0;
this["pic_mc" b_num]._y = 0;
this["pic_mc" b_num].swapDepths(-this["pic_mc" b_num].getDepth());
this["pic_mc" b_num].enabled = false;
}
};
////////////
mc._visible = false;
}
/////////////////////////////
var listener:Object = new Object();
////////
var loadpic:MovieClipLoader = new MovieClipLoader();
listener.onLoadInit = function(target:MovieClip) {
target._width = Stage.width;
target._height = Stage.height;
fuwei_func();
wh_txt1.text = "";
wh_txt2.text = "";
Selection.setFocus("wh_txt1");
};
loadpic.addListener(listener);
/////////////////
var fileRef:FileReference = new FileReference();
var allTypes:Array = [];
var 浏览类型:Object = new Object();
浏览类型.description = "浏览类型(*.jpg)";
浏览类型.extension = "*.jpg";
allTypes.push(浏览类型);
listener.onSelect = function(file:FileReference) {
loadpic.loadClip("/" file.name, mc);
};
fileRef.addListener(listener);
/////////////////////////
var pic_menu:ContextMenu = new ContextMenu();
function browse_func() {
fileRef.browse(allTypes);
}
pic_menu.hideBuiltInItems();
var loadpic_menu:ContextMenuItem = new ContextMenuItem("加载新图片", browse_func);
pic_menu.customItems.push(loadpic_menu);
_root.menu = pic_menu;
分割图片.rar我的参考资料来自与帮助文档,当然自己也经过了一些研究.现在所发布的是一个很完整的FLEX播放器,如果你有更多的想法,你可以对此进行修改,或者扩展开发你想要的内容.
代码里我还注释了详细的说明.有说的不对的地方,请指正一下,如果你有更好的开发,希望你也能够告诉我,互相学习嘛.
最后申明下:我这里的东西都是原创,或者借签了一些开发人员的小TIP程序.当然,当然,还是希望你喜欢这个程序.
var constants:Number =1;
然后点击面板上的代码排列图标,你就会发现排列错误信息. 我测试了几遍,发现只要有constant字节,排列肯定会出错..哈哈。有兴趣的可以测试一下啊
虽然,我用了ALPHA 9 ALPHA版本已经过了半年了,最关心的还是代码的写法,在正式版本里头,AS3.0到底与2.0有多少的区别?组件到底如何?
今天刚好有人问我TEXTFIELD的区别。于是,我就测试了下。很有意思的是,在字体里有,竟然有一个字体叫"明朝",实在不明白是什么意思.呵呵。要注意的是,在明朝上头的那个日本字体,容易让机器停顿一下。看来有点问题.那么我就先测试一下那个明朝字体.
用最传统的贞上写代码(AS3已经不推荐这样写了)方式来看看,首先在舞台上放一个动态文本,把Instance Name定义为"t",字体设置为"明朝",大小为12 .然后新建一层命名"ACTION"写上以下代码:
t.text = "你好,我是中国人,不是外国人";
t.autoSize = TextFieldAutoSize.LEFT;
t.background = true;
t.border = true;
var tformat:TextFormat = new TextFormat();
tformat.color = 0xFF0000;
tformat.size = 12;
tformat.underline = true;
t.setTextFormat(tformat);
结果是很有趣的,在AS2和AS3里头都能测试出来. 当然这只是最简单的代码,更多的区别还是需要自己去研究下.
但是需要说的是,如果用动态遮罩文本的话,用中文字体库绑定,还是需要很大.这是个问题.有待改善啊...

In my previous post, I provided an example of an Apollo application using the Flex Message Service. Since then, a number of people have asked for examples of Apollo applications accessing data using the Flex Data Management services. So here is a simple Contact Management application that demonstrates this integration.
Using the Data Services to work with data in Apollo offers several benefits. First, just like for traditional browser-based Flex apps, the Data Management Services automate the synchronization of data between the client and the middle-tier. In other words, you don’t have to flag/keep track of the changes made at the client-side, and then make corresponding RPC calls to send changes to the server: all that is managed automatically.
For this application, I actually used LiveCycle Data Services (the new name for Flex Data Services) 2.5 currently in beta 2, which offer additional benefits in the context of this application:
- Using the new SQL assembler, you don’t have to write server-side components if you don’t want/need to: you just provide a series of SQL statements indicating how data should be retrieved, and how changes should be persisted in the database. The SQL assembler makes it extremely fast and easy to create applications that don’t require sophisticated persistence logic.
- In 2.5, the DataService API provides methods (such as dataService.saveCache() / dataService.clearCache()) to save data locally and manipulate the local data store. You can also automatically synchronize the changes you made offline with the server. I ran into a bug in LCDS beta 2 that prevented me from implementing offline caching in this sample. The bug is fixed post beta 2 and I will share an updated version of the app when the bits become publicly available.
Installation instructions:
- Install LiveCycle Data Services 2.5 beta here
- Modify the flexdemosb database file to add the contact table: replace WEB-INF\db\flexdemodb\flexdemodb.script with this version.
- Open WEB-INF\flex\data-management-config.xml and add the following destination.
<destination id="sql-contact">
<adapter ref="java-dao" />
<properties>
<use-transactions>true</use-transactions>
<source>flex.data.assemblers.SQLAssembler</source>
<scope>application</scope>
<metadata>
<identity property="CONTACT_ID"/>
</metadata>
<network>
<session-timeout>20</session-timeout>
<paging enabled="false" pageSize="10" />
<throttle-inbound policy="ERROR" max-frequency="500"/>
<throttle-outbound policy="REPLACE" max-frequency="500"/>
</network>
<server>
<database>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<url>jdbc:hsqldb:file:C:/lcds/jrun4/servers/default/samples/WEB-INF/db/flexdemodb/flexdemodb</url>
<username>sa</username>
<password></password>
<login-timeout>15</login-timeout>
</database>
<actionscript-class>Contact</actionscript-class>
<fill>
<name>all</name>
<sql>SELECT * FROM CONTACT</sql>
</fill>
<get-item>
<sql>SELECT * FROM CONTACT WHERE CONTACT_ID = #CONTACT_ID#</sql>
</get-item>
<create-item>
<sql>INSERT INTO CONTACT (FIRST_NAME,LAST_NAME,EMAIL,PHONE,ADDRESS,CITY,STATE,ZIP,COUNTRY,NOTES) VALUES (#FIRST_NAME#, #LAST_NAME#, #EMAIL#, #PHONE#, #ADDRESS#, #CITY#, #STATE#, #ZIP#, #COUNTRY#, #NOTES#)</sql>
<id-query>CALL IDENTITY()</id-query>
</create-item>
<update-item>
<sql>UPDATE CONTACT SET FIRST_NAME=#FIRST_NAME#, LAST_NAME=#LAST_NAME#, EMAIL=#EMAIL#, PHONE=#PHONE#, ADDRESS=#ADDRESS#, CITY=#CITY#, STATE=#STATE#, ZIP=#ZIP#, COUNTRY=#COUNTRY#, NOTES=#NOTES# WHERE CONTACT_ID=#_PREV.CONTACT_ID#</sql>
</update-item>
<delete-item>
<sql>DELETE FROM CONTACT WHERE CONTACT_ID=#CONTACT_ID#</sql>
</delete-item>
<count>
<name>all</name>
<sql>SELECT count(*) FROM CONTACT</sql>
</count>
</server>
</properties>
</destination>






