|
-
as3 Dynamic text add tweens.
Hello. There's the situation - I'm trying to create the dynamic xml main menu with the sublinks generated by xml. It's seemes to be ok with the menu. But there's the only thing that makes me stuck - I can't get a glue of how to add the tween to the submenue's text on mouse over? I'd like it to change the font size easily, not instantly like it is now.
Here's the code:
import flash.text.*;
import flash.media.*;
import flash.display.*; // (Sprite, Graphics, Shape)
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.*;
import com.greensock.*;
import com.greensock.easing.*;
import caurina.transitions.*;
import com.utils.CallArg;
//import com.chewtinfoil.utils.StringUtils;
//backPanelMain.visible = false;
backPanelMain.alpha = 0;
// Initial Variables for centering the mainlinks
var mainLinkLeftMargin:Number = 700;
var mainLinkPadding:Number = 200;
var subLinkLeftMargin:Number = 500;
var subLinkPadding:Number = 3;
// FORMATTING TextFields
var textFormatMain:TextFormat = new TextFormat();
textFormatMain.color = 0xffffff;
textFormatMain.size = 11;
textFormatMain.align = TextFormatAlign.CENTER;
textFormatMain.letterSpacing = -0.5;
textFormatMain.bold = true;
textFormatMain.font = "Tahoma, Verdana";
var textFormatMainUp:TextFormat = new TextFormat();
textFormatMainUp.color = 0xc6c5a9;
textFormatMainUp.size = 11;
textFormatMain.align = TextFormatAlign.CENTER;
textFormatMainUp.letterSpacing = -0.5;
textFormatMainUp.bold = true;
textFormatMainUp.font = "Tahoma, Verdana";
var textFormatSub:TextFormat = new TextFormat();
textFormatSub.color = 0x333333;
textFormatSub.size = 10;
textFormatSub.align = TextFormatAlign.CENTER;
textFormatSub.letterSpacing = -1.1;
textFormatSub.bold = true;
textFormatSub.font = "Verdana,Tahoma";
var textFormatSubUp:TextFormat = new TextFormat();
textFormatSubUp.color = 0x959A77;
textFormatSubUp.size = 11;
textFormatSub.align = TextFormatAlign.CENTER;
textFormatSubUp.letterSpacing = -1.1;
textFormatSubUp.bold = true;
textFormatSubUp.font = "Verdana,Tahoma";
stop();
// general settings
var xmlFilename:String = "mainmenu.xml";
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
var xml:XML;
xmlLoader.load(new URLRequest(xmlFilename));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
var myIconsArray:Array = new Array();
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
for (var i:int =0 ; i<xmlList.length() ; i++)
{
// for the first element there is no previous textfield inserted
if (i==0)
{
createMainText(xmlList[i].attribute("title"), xmlList[i].attribute("link") , mainLinkLeftMargin , 0 , 0 );
createSublinks(xmlList,i);
}
else
{
// Create the text field getting positioning setting form the previous textField inserted
createMainText(xmlList[i].@title, xmlList[i].attribute("link") ,getChildByName("mainLink"+(i-1).toString()).width + 15 + getChildByName("mainLink"+(i-1).toString()).x + subLinkPadding, 0 , i );
createSublinks(xmlList,i);
}
}
// effect
Tweener.addTween(backPanelMain, {alpha:1, time:2, transition:"strong"});
stage.addEventListener(Event.MOUSE_LEAVE, hideAllSubLinks);
}
function createMainText(mainText:String, mainLink:String, xPosition:Number, yPosition:Number, indexNumber:Number):void{
var dynText:TextField = new TextField();
dynText.name = "mainLink" + indexNumber.toString();
dynText.selectable = false;
dynText.x = xPosition;
dynText.y = yPosition;
dynText.autoSize = TextFieldAutoSize.LEFT;
dynText.text = mainText;
dynText.setTextFormat(textFormatMain);
addChild(dynText);
setChildIndex(dynText,numChildren - 1);
//getChildByName("mainLink" + indexNumber.toString()).addEventListener(MouseEven t.MOUSE_OVER, subLinksShow(indexNumber));
dynText.addEventListener(MouseEvent.MOUSE_OVER, subLinksShow);
dynText.addEventListener(MouseEvent.MOUSE_OVER, buttonModeTrue);
dynText.addEventListener(MouseEvent.MOUSE_OUT, buttonModeFalse);
getChildByName("mainLink" + indexNumber.toString()).addEventListener(MouseEven t.CLICK, CallArg.create(gotoSub, mainLink));
}
function buttonModeTrue(event:Event):void
{
event.target.setTextFormat(textFormatMainUp);
}
function buttonModeFalse(event:Event):void
{
event.target.setTextFormat(textFormatMain);
}
function createSublinks(xmlList:XMLList, indexSub:Number):void{
for (var i:int =0 ; i<xmlList[indexSub].sublink.length() ; i++)
{
if (i==0)
{
createSublink(xmlList[indexSub].sublink[i].@title, xmlList[indexSub].sublink[i].@link, -3, subLinkLeftMargin ,indexSub ,i);
}
else
{
createSublink(xmlList[indexSub].sublink[i].@title, xmlList[indexSub].sublink[i].@link, -3, getChildByName("sublink" + (indexSub).toString() + "_" + (i-1).toString()).width + getChildByName("sublink" + (indexSub).toString() + "_" + (i-1).toString()).x + subLinkPadding ,indexSub ,i);
}
}
}
function createSublink(textSub:String, linkSub:String, positionY:Number,positionX:Number, mainIndexNumber:Number,subIndexNumber:Number ):void{
var dynTextSub:TextField = new TextField();
dynTextSub.name = "sublink" + mainIndexNumber.toString() + "_" + subIndexNumber.toString();
dynTextSub.selectable = false;
dynTextSub.x = positionX;
dynTextSub.y = positionY;
dynTextSub.autoSize = TextFieldAutoSize.LEFT;
dynTextSub.text = textSub;
dynTextSub.setTextFormat(textFormatSub);
addChild(dynTextSub);
setChildIndex(dynTextSub,0);
getChildByName( "sublink" + mainIndexNumber.toString() + "_" + subIndexNumber.toString()).addEventListener(MouseE vent.CLICK, CallArg.create(gotoSub, linkSub));
dynTextSub.addEventListener(MouseEvent.MOUSE_OVER, buttonModeSubTrue);
dynTextSub.addEventListener(MouseEvent.MOUSE_OUT, buttonModeSubFalse);
}
function buttonModeSubTrue(event:Event):void
{
event.target.setTextFormat(textFormatSubUp);
}
function buttonModeSubFalse(event:Event):void
{
event.target.setTextFormat(textFormatSub);
}
function gotoSub(_event:Event, link):void
{
navigateToURL(new URLRequest(link), "_self");
//trace(link);
}
function subLinksShow(event:Event):void
{
var indexMain:Number = Number(event.target.name.replace("mainLink",""));
var subChild:Number;
//hide all other Sublinks which index is nor indexMain
for(var k:Number = 0 ; k < xmlList.length() ; k++)
{
if (k!=indexMain)
{
for( var j2:Number = 0; j2 < xmlList[k].sublink.length(); j2++)
{
Tweener.addTween(getChildByName("sublink" + k.toString() + "_" + j2.toString()), {alpha: .1, y:0, time:1.1, transition:""});
}
}
}
// find the Sublinks and show them
for( var j:Number = 0; j < xmlList[indexMain].sublink.length(); j++)
{
Tweener.addTween(getChildByName("sublink" + indexMain.toString() + "_" + j.toString()), {alpha: 1, y:15, time:0.8, transition:""});
}
}
function hideAllSubLinks(event:Event):void
{
for(var k:Number = 0 ; k < xmlList.length() ; k++)
{
for( var j:Number = 0; j < xmlList[k].sublink.length(); j++)
{
Tweener.addTween(getChildByName("sublink" + k.toString() + "_" + j.toString()), {alpha: .1, y:0, time:4, transition:""});
}
}
}
Thanx in advance.
-
rabid_Delineator
So wait , you want to tween the pt size of the font ?
-
 Originally Posted by AttackRabbit
So wait , you want to tween the pt size of the font ?
Well, not at all. I'm trying to make the text area flip as well as the button area does. It doesn't seem to work correctly - the text field is getting distorted the randow way...
Now I've solved the tint and the transform animation for the menuFill button with the Tweenmax and now I'd like the text to be transformed the same way...
function mouseOutItem(e:Event):void {
//Get the item that dispatched the event
var item:MenuItem = e.target as MenuItem;
//Tween the tint
TweenMax.to(item.menuFill, 0.5, {removeTint:true,ease:Sine.easeIn, delay:0.3});
TweenMax.to(item.menuFill, 0.4, {startAt:{scaleY:-0.5}, transformAroundCenter:{scaleY:1}, ease:Strong.easeOut, delay:0.3});
//TweenMax.to(item.menuText, 0.4, {startAt:{scaleY:-0.5}, transformAroundPoint:{point:new Point(0,35), scaleY:1}, ease:Strong.easeOut, delay:0.1});
}
-
 Originally Posted by AttackRabbit
So wait , you want to tween the pt size of the font ?
And I'd appreciate if you helped me with the font size tweening as well. I've got the other menu to meet that effect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|