热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ActionScript3圆形文本字段

篇首语:本文由编程笔记#小编为大家整理,主要介绍了ActionScript 3 圆形文本字段相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了ActionScript 3 圆形文本字段相关的知识,希望对你有一定的参考价值。




/*
Usage from other .as file:
public var inputText:String = "Lorem ipsum dolor sit amet%newline%, consectetur adipiscing elit. Donec hendrerit adipiscing quam, eu suscipit arcu mattis eget. Curabitur consectetur eleifend magna id scelerisque. Etiam congue condimentum leo ac lacinia. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed aliquet justo. Nunc dapibus massa ut justo elementum et vestibulum justo suscipit.";
roundTextField = new RoundedTextField(inputText);
addChild(roundTextField);
*/
package
{
import caurina.transitions.Tweener;

import flash.display.BlendMode;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
/**
* @author mparzinski (twitter: @withinmedianl)
* INSTRUCTIONS
* - parameters (input, circleSize, margin, startY, endY, font, fontSize, lineHeight, backgroundColor, backgroundAlpha)
* - input: The text that should be placed in the roundedtextfield
* - circlesize: The size of the circle (from center to side, so 75 gives a circle of 150px)
* - margin: The margin in px from the sides of the circle to the text
* - startY: topmargin (snaps to textfield's height)
* - endY: bottomMargin (snaps to textfield's height)
* - font: font used in the textfield
* - fontSize: size of the font in px
* - lineHeight: height of a line of text
* - backgroundColor: color of the circle (0xRRGGBB)
* - backgroundAlpha: alpha of the circle (0 - 1)
* - animate (boolean) should the clip animate in?
* //////////////////////////////////////////////////////////////
* SPECIALS
* - %newline% in input for a linebreak (dont work on autosize)
* - circlesize to "-1" for autoSize
* //////////////////////////////////////////////////////////////
*/
public class RoundedTextField extends Sprite
{
public var defaultCircleSize:Number;
public var defaultMargin:Number;
public var defaultStartY:Number;
public var defaultEndY:Number;
public var defaultFont:String;
public var defaultFontSize:Number;
public var defaultLineHeight:Number;
public var defaultBackgroundColor:Number;
public var defaultBackgroundAlpha:Number;
public var defaultAnimate:Boolean;

private var autoSize:Boolean;

public var currentTargetIndex:Number;
public var currentTargetNextY:Number;
public var placedChars:Number;
public var difference:Number;

public var circleSprite:Sprite;
public var squareSprite:Sprite;
public var textFieldSize:Sprite;

public var textFormat:TextFormat;
public var currentTarget:TextField;
public var textFields:Array;

// Constructor
public function RoundedTextField(
input:String,
circleSize:Number = 210,
margin:Number = 15,
startY:Number = 10,
endY:Number = 30,
font:String = "Arial",
fontSize:Number = 13,
lineHeight:Number = 17,
backgroundColor:uint = 0xB3E7FB,
backGroundAlpha:Number = 1,
animate:Boolean = true
):void
{
if(circleSize != -1)
{
defaultCircleSize = circleSize;
autoSize = false;
}
else
{
defaultCircleSize = 50;
autoSize = true;
}
defaultMargin = margin;
defaultStartY = startY;
defaultEndY = endY;
defaultFOnt= font;
defaultFOntSize= fontSize;
defaultLineHeight = lineHeight;
defaultBackgroundColor = backgroundColor;
defaultBackgroundAlpha = backGroundAlpha;
defaultAnimate = animate;

textFormat = new TextFormat();
textFormat.fOnt= defaultFont;
textFormat.size = defaultFontSize;
textFormat.align = TextFormatAlign.CENTER;

init(input);
}
public function init(input:String):void
{
currentTargetNextY = (-defaultCircleSize) + defaultStartY + defaultLineHeight;
currentTargetIndex = 0;
placedChars = 0;
textFields = new Array();

// draw the background circle
circleSprite = new Sprite;
circleSprite.graphics.beginFill(defaultBackgroundColor, defaultBackgroundAlpha);
circleSprite.graphics.drawCircle(0, 0, defaultCircleSize);
circleSprite.graphics.endFill();
addChild(circleSprite);

addTextFields();

trace("input length; " + input.length);
enterText(input);
}
private function addTextFields():void
{
trace("adding Textfields");
while(currentTargetNextY {
var tf:TextField = new TextField();
tf.defaultTextFormat = textFormat;
tf.wordWrap = true;
tf.multiline = false;
tf.autoSize = TextFieldAutoSize.LEFT;

tf.y = currentTargetNextY;
var futureTextFieldW:Number;
var tfy:Number;
if(currentTargetNextY <0)
{
tfy = Math.abs(tf.y);
futureTextFieldW= Math.sqrt((defaultCircleSize * defaultCircleSize) - (tfy * tfy));
}
else
{
tfy = Math.abs(tf.y + defaultLineHeight);
futureTextFieldW= Math.sqrt((defaultCircleSize * defaultCircleSize) - (tfy * tfy));
}

tf.width = (futureTextFieldW * 2) - defaultMargin;
tf.x = -tf.width / 2; // centers the textfield (x)
tf.name = tf.name + Math.floor(tf.width);

addChild(tf);

currentTargetNextY += defaultLineHeight;
textFields.push(tf);
}
}
private function enterText(input:String):void
{
currentTarget = textFields[currentTargetIndex] as TextField;
for(var i:Number = 0; i {
if(currentTarget.textWidth + (defaultMargin * 5) > currentTarget.width )
{
if(input.substring(i, i + 1) == " ")
{
if(currentTargetIndex {
currentTargetIndex += 1;
currentTarget = textFields[currentTargetIndex] as TextField;
}
else
{
if(autoSize == true)
{
trace("Restarting, not enough space");
restart(input);
}
else
{
currentTarget.appendText("...");
}
difference = input.length - placedChars;

if(defaultAnimate == true)
{
animate();
}
return;
}
}
}
// look for a line break, add a new textfield and delete the %newline% from the inputtext
if(input.substring(i, i + 9) == "%newline%")
{
trace("found newline");
currentTargetIndex += 1;
currentTarget = textFields[currentTargetIndex] as TextField;
input = input.substring(0, i) + input.substring(i + 9, input.length);
}
if(i == input.length)
{
for(var x:Number = 0; i {
if(textFields[x].text.length == 1)
{
removeChildAt(x + 1);
}
}
}
currentTarget.appendText(input.substring(i, i + 1)); // add 1 character to the textfield
placedChars += 1;
currentTarget.multiline = false;
}
}

private function restart(input:String):void
{
while(numChildren)
{
removeChildAt(0);
}
defaultCircleSize += defaultMargin;
init(input);
}

private function animate():void
{
trace("starting animation");
circleSprite.scaleY = .8;
circleSprite.scaleX = .8;

for(var i:Number = 0; i {
var target:Object = getChildAt(i);
target.alpha = 0;

Tweener.addTween(target, {
alpha: 1,
delay: .5 / i,
time: 1.5 / i,
transition: "easeInBack" });
}
Tweener.addTween(circleSprite, {
alpha: defaultBackgroundAlpha, delay: .2, time: .5, transition: "easeOutBack" });
Tweener.addTween(circleSprite, {
scaleX: 1, delay: .2, time: .5, transition: "easeOutBack" });
Tweener.addTween(circleSprite, {
scaleY: 1, delay: .19, time: .49, transition: "easeInBack" });
}
}
}


推荐阅读
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了Kotlin中扩展函数的一些惯用用法以及其合理性。作者认为在某些情况下,定义扩展函数没有意义,但官方的编码约定支持这种方式。文章还介绍了在类之外定义扩展函数的具体用法,并讨论了避免使用扩展函数的边缘情况。作者提出了对于扩展函数的合理性的质疑,并给出了自己的反驳。最后,文章强调了在编写Kotlin代码时可以自由地使用扩展函数的重要性。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 开发笔记:实验7的文件读写操作
    本文介绍了使用C++的ofstream和ifstream类进行文件读写操作的方法,包括创建文件、写入文件和读取文件的过程。同时还介绍了如何判断文件是否成功打开和关闭文件的方法。通过本文的学习,读者可以了解如何在C++中进行文件读写操作。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 本文介绍了如何使用Express App提供静态文件,同时提到了一些不需要使用的文件,如package.json和/.ssh/known_hosts,并解释了为什么app.get('*')无法捕获所有请求以及为什么app.use(express.static(__dirname))可能会提供不需要的文件。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
author-avatar
叶葳蕤1095190287
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有