求问这段AS3代码写在FLASH时间轴上该怎么写?
这里有字数限制写不下,所以复制在了这贴吧地址上http://tieba.baidu.com/p/2372980980不胜感激!!...
这里有字数限制写不下,所以复制在了这贴吧地址上
http://tieba.baidu.com/p/2372980980
不胜感激!! 展开
http://tieba.baidu.com/p/2372980980
不胜感激!! 展开
展开全部
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.text.TextFormat;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.text.TextField;
[SWF(width = "465",height = "465",frameRate = "60",backgroundColor = "#ffffff")]
const TEXT:String = "显示文字";
function Main() {
var hairyText:DisplayObject = createHairyText(TEXT,new TextFormat(null,100),0.5);
hairyText.x = ( stage.stageWidth - hairyText.width ) / 2;
hairyText.y = ( stage.stageHeight - hairyText.height ) / 2;
addChild( hairyText );
}
function createHairyText( text:String, textFormat:TextFormat = null, limit:Number = 1, longHairLength:Number = 0, alpha:Number = 0.5 ):DisplayObject {
if (! textFormat) {
textFormat = new TextFormat();
}
if (! longHairLength) {
longHairLength = ( ( textFormat.size ) ? Number( textFormat.size ) : 12 ) / 10;
}
var bitmapData:BitmapData = textToBitmapData(text,textFormat);
var sprite:Sprite = new Sprite();
var graphics:Graphics = sprite.graphics;
graphics.clear();
graphics.lineStyle( 0, uint( textFormat.color ), alpha );
for (var i:uint = 0; i < ( bitmapData.width * bitmapData.height ) * limit; i++) {
var x:uint = (limit != 1) ? Math.random() * bitmapData.width:i % bitmapData.width;
var y:uint = ( limit != 1 ) ? Math.random() * bitmapData.height : uint( i / bitmapData.width );
var color32:uint = bitmapData.getPixel32(x,y);
if ( color32 == 0 ) {
//Anchor point so that the hair goes outer.
var hairLength:Number = longHairLength * Math.random();
var hairRadian:Number = Math.random() * 2 * Math.PI;
var anchorX:Number = x + hairLength * Math.cos(hairRadian);
var anchorY:Number = y + hairLength * Math.sin(hairRadian);
//Control point for the Bezier curve.
var controlDistance:Number = longHairLength * Math.random();
var controlRadian:Number = Math.random() * 2 * Math.PI;
var controlX:Number = x + controlDistance * Math.cos(controlRadian);
var controlY:Number = y + controlDistance * Math.sin(controlRadian);
graphics.moveTo( x, y );
graphics.curveTo( controlX, controlY, anchorX, anchorY );
}
}
return sprite;
}
function textToBitmapData( text:String, textFormat:TextFormat = null ):BitmapData {
var textField:TextField = new TextField();
textField.text = text;
if (textFormat) {
textField.setTextFormat( textFormat );
}
textField.width = textField.textWidth + 2 * 2;
textField.height = textField.textHeight + 2 * 2;
var bitmapData:BitmapData = new BitmapData(textField.width - 2 * 2,textField.height - 2 * 2,true,0);
bitmapData.draw( textField, new Matrix(1, 0, 0, 1, -2, -2) );
return bitmapData;
}
Main();
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.text.TextFormat;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.text.TextField;
[SWF(width = "465",height = "465",frameRate = "60",backgroundColor = "#ffffff")]
const TEXT:String = "显示文字";
function Main() {
var hairyText:DisplayObject = createHairyText(TEXT,new TextFormat(null,100),0.5);
hairyText.x = ( stage.stageWidth - hairyText.width ) / 2;
hairyText.y = ( stage.stageHeight - hairyText.height ) / 2;
addChild( hairyText );
}
function createHairyText( text:String, textFormat:TextFormat = null, limit:Number = 1, longHairLength:Number = 0, alpha:Number = 0.5 ):DisplayObject {
if (! textFormat) {
textFormat = new TextFormat();
}
if (! longHairLength) {
longHairLength = ( ( textFormat.size ) ? Number( textFormat.size ) : 12 ) / 10;
}
var bitmapData:BitmapData = textToBitmapData(text,textFormat);
var sprite:Sprite = new Sprite();
var graphics:Graphics = sprite.graphics;
graphics.clear();
graphics.lineStyle( 0, uint( textFormat.color ), alpha );
for (var i:uint = 0; i < ( bitmapData.width * bitmapData.height ) * limit; i++) {
var x:uint = (limit != 1) ? Math.random() * bitmapData.width:i % bitmapData.width;
var y:uint = ( limit != 1 ) ? Math.random() * bitmapData.height : uint( i / bitmapData.width );
var color32:uint = bitmapData.getPixel32(x,y);
if ( color32 == 0 ) {
//Anchor point so that the hair goes outer.
var hairLength:Number = longHairLength * Math.random();
var hairRadian:Number = Math.random() * 2 * Math.PI;
var anchorX:Number = x + hairLength * Math.cos(hairRadian);
var anchorY:Number = y + hairLength * Math.sin(hairRadian);
//Control point for the Bezier curve.
var controlDistance:Number = longHairLength * Math.random();
var controlRadian:Number = Math.random() * 2 * Math.PI;
var controlX:Number = x + controlDistance * Math.cos(controlRadian);
var controlY:Number = y + controlDistance * Math.sin(controlRadian);
graphics.moveTo( x, y );
graphics.curveTo( controlX, controlY, anchorX, anchorY );
}
}
return sprite;
}
function textToBitmapData( text:String, textFormat:TextFormat = null ):BitmapData {
var textField:TextField = new TextField();
textField.text = text;
if (textFormat) {
textField.setTextFormat( textFormat );
}
textField.width = textField.textWidth + 2 * 2;
textField.height = textField.textHeight + 2 * 2;
var bitmapData:BitmapData = new BitmapData(textField.width - 2 * 2,textField.height - 2 * 2,true,0);
bitmapData.draw( textField, new Matrix(1, 0, 0, 1, -2, -2) );
return bitmapData;
}
Main();
追问
啊。。。为什么我复制进去后显示“1084: 语法错误: rightbrace 应在 end of program 之前。”?
追答
你是不是复制少了东西?注意度娘的分行问题。
附件为我改完写在帧上面的。打开要求 CS5.5以上(出现兼容问题,无视)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询