Autor Zpráva
honza009
Profil
Ahoj,

stáhl jsem si jedno hotové řešení textového tickeru, který je napojen na xml soubor a potřeboval bych zajistit, aby se jednotlivé tagy vypisovaly hned po sobě. Mohl by mi někdo poradit, jak na to? Pracuji se statickou grafikou a actionscript mi opravdu nic neříká. Říkejte to ale šéfovi :)

Díky moc za případnou pomoc!

Zde AS (konkrétně pak funkce sliderticker - basic_ticker) :


package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.utils.getTimer;

public class TickerSprite extends Sprite
{
static const kEffectDuration = 2000;
static const kReadDuration = 2000;

public static var mcCtr = 0;
static var tickerItems = [];
static var tickerMCs = [];
static var tickerIdx = 0;


var mc:ticker_mc;

var speed;
var isMouseIn;
var idx;
var srcScale, srcX, srcY, srcAlpha, dstScale, dstX, dstY, dstAlpha;
var startTime;
var tstate = -1;

public function TickerSprite(idx)
{
mc = new ticker_mc();
this.idx = idx;
addChild(mc);
mc.ticker_txt.autoSize = "left";
// mc.ticker_txt.html = true;
speed = 5;
isMouseIn = false;
addEventListener(MouseEvent.MOUSE_MOVE, myMouseMove);
addEventListener(Event.ENTER_FRAME, cycleTicker);

}

public static function setTickerItems(itsItems)
{
tickerItems = itsItems;
}

public static function addTickerItem(itsItem)
{
tickerItems.push(itsItem);
}

public static function startTicker(parMC)
{
var mc = new TickerSprite(0);
parMC.addChild(mc);
tickerMCs.push(mc);

mc = new TickerSprite(1);
parMC.addChild(mc);
tickerMCs.push(mc);

tickerMCs[0].getTickerItem(0);
tickerMCs[1].visible = false;
}

function myMouseMove(evt)
{
if (mouseY <= stage.stageHeight/3 && mouseY >= -stage.stageHeight/3)
{
speed = 5;
isMouseIn = true;
}
}

function setTweenTargets(dstX,dstY,dstScale,dstAlpha)
{
this.srcScale = this.scaleX;
this.srcX = this.x;
this.srcY = this.y;
this.srcAlpha = this.alpha;

this.dstScale = dstScale;
this.dstX = dstX;
this.dstY = dstY;
this.dstAlpha = dstAlpha;
}

function setupDebut(n)
{
this.startTime = getTimer();
if (n == undefined || n == 'scroll' || n == '') { // basic leftwards scroll effect
mc.ticker_txt.x = 0;
mc.ticker_txt.y = -mc.ticker_txt.textHeight/2;
this.scaleX = 1;
this.scaleY = 1;
this.alpha = 1;
this.x = stage.stageWidth;
this.y = stage.stageHeight/2;
this.tstate = -1;
}
else {
mc.ticker_txt.x = -mc.ticker_txt.textWidth/2;
mc.ticker_txt.y = -mc.ticker_txt.textHeight/2;

switch (n) {
case 'left': // from left
this.alpha = 1;
this.x = -mc.ticker_txt.textWidth/2;
this.y = stage.stageHeight/2;
this.scaleY = this.scaleX = stage.stageWidth/(mc.ticker_txt.textWidth+20);
setTweenTargets(stage.stageWidth/2, this.y, this.scaleX,1);
break;
case 'right': // from right
this.alpha = 1;
this.x = stage.stageWidth+mc.ticker_txt.textWidth/2;
this.y = stage.stageHeight/2;
this.scaleY = this.scaleX = Math.min(1,stage.stageWidth/(mc.ticker_txt.textWidth+20));
setTweenTargets(stage.stageWidth/2, this.y, this.scaleX,1);
break;
case 'top': // from top
case 'up':
this.x = stage.stageWidth/2;
this.y = 0 - mc.ticker_txt.textHeight/2;
this.scaleY = this.scaleX = Math.min(1,stage.stageWidth/(mc.ticker_txt.textWidth+20));
this.alpha = 1;
setTweenTargets(this.x, stage.stageHeight/2, this.scaleX,1);
break;
case 'down': // from bottom
case 'bottom':
this.alpha = 1;
this.x = stage.stageWidth/2;
this.y = stage.stageHeight+mc.ticker_txt.textHeight;
this.scaleY = this.scaleX = Math.min(1,stage.stageWidth/(mc.ticker_txt.textWidth+20));
setTweenTargets(this.x, stage.stageHeight/2, this.scaleX,1);
break;
case 'in': // 3d fly-in/out from small
case 'tiny':
this.alpha = 0;
this.x = stage.stageWidth/2;
this.y = stage.stageHeight/2;
this.scaleX = this.scaleY = .01;
setTweenTargets(this.x, this.y, Math.min(1,stage.stageWidth/(mc.ticker_txt.textWidth+20)),1);
break;
case 'out': // 3d fly-in/out from large
case 'big':
this.alpha = 0;
this.x = stage.stageWidth/2;
this.y = stage.stageHeight/2;
this.scaleY = this.scaleX = stage.stageWidth*10/(mc.ticker_txt.textWidth+20);
setTweenTargets(this.x, this.y, Math.min(1,stage.stageWidth/(mc.ticker_txt.textWidth+20)),1);
break;
default:
trace("debut: undefined type for " + this.idx + " : " + n);
}
}
}

function setupExit(n)
{
this.startTime = getTimer();
switch (n) {
case 'left': // exit to left
setTweenTargets(-mc.ticker_txt.textWidth/2, this.y, this.scaleX,1);
break;
case 'right': // exit to right
setTweenTargets(stage.stageWidth+mc.ticker_txt.textWidth/2, this.y, this.scaleX,1);
break;
case 'up': // exit up
case 'top':
setTweenTargets(this.x, -mc.ticker_txt.textHeight/2, this.scaleX,1);
break;
case 'down': // exit down
case 'bottom':
case 'bot':
setTweenTargets(this.x, stage.stageHeight+mc.ticker_txt.textHeight/2, this.scaleX,1);
break;
case 'small': // exit small
case 'in':
setTweenTargets(this.x, this.y, .01, 0);
break;
case 'big': // exit big
case 'out':
setTweenTargets(this.x, this.y, stage.stageWidth*100/(mc.ticker_txt.textWidth+20), 0);
break;
default:
trace("exit: undefined type for " + this.idx);
}
}

public function getTickerItem(n)
{
visible = true;
this.idx = n;
this.tstate = 0;
mc.ticker_txt.htmlText = tickerItems[n].txt;
setupDebut(tickerItems[n].debut);
}

// This function animates the text
//
function cycleTicker(evt)
{
if (!visible)
return;

var queueNext = false;
var r;
switch (tstate) {
case -1: // regular scroll, as in basic_ticker
this.x -= this.speed;
queueNext = (this.x <= -mc.ticker_txt.textWidth);
if (queueNext)
this.visible = false;
break;
case 0: // debut effect?
case 2: // or exit effect?

// Figure out where in the tween we are
r = (getTimer() - this.startTime)/kEffectDuration;
if (r >= 1) { // Done tweening? set vars to final state and move on
this.scaleX = this.scaleY = this.dstScale;
this.alpha = this.dstAlpha;
this.x = this.dstX;
this.y = this.dstY;
this.startTime = getTimer();
this.tstate++;
if (this.tstate >= 3)
this.visible = false;
// trace(" state " + this.state);
}
else if (r < 0) { // shouldn't happen
trace(" negative r! " + r + " " + this.startTime + " " + getTimer());
}
else {
// ease out for exit effects, or ease in for debut effects
if ((tstate == 0 && r > .5) || (tstate == 2 && r < .5))
{
r = r*r*(3-2*r);
r = r*r*(3-2*r);
}
this.scaleX = this.scaleY = this.srcScale + (this.dstScale-this.srcScale)*r;
this.x = this.srcX + (this.dstX - this.srcX)*r;
this.y = this.srcY + (this.dstY - this.srcY)*r;
this.alpha = this.srcAlpha + (this.dstAlpha - this.srcAlpha)*r;
}
break;
case 1: // read pause
r = (getTimer() - this.startTime)/kReadDuration;
if (r > 1 && this.isMouseIn != true)
{
queueNext = true;
this.tstate++;
this.setupExit(tickerItems[this.idx].exit);
}
break;
default:
trace(" unsupported state " + this.state);
}
if (queueNext)
{
mcCtr = (mcCtr + 1) % 2;
tickerIdx = (tickerIdx+1) % tickerItems.length;
tickerMCs[mcCtr].getTickerItem(tickerIdx);
}
}

} // end class


} // end package
[/pre]

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0