XML を取り込み、ループでバナーを吐き出すフラッシュ ムービーがあります。ただし、バナーに「go to」バナーリンク、つまり1 2 3 4 5などを提供するボタンのリストを配置することにより、カルーセルスタイルの機能を提供する必要があります。
xml をループして goto リンクを作成するので、ムービー クリップを作成することができますが、これはクリック機能に問題があります。基本的に、新しく作成されたムービー クリップ ボタンを対象としています。
関数 creaBottone は、配列から渡された番号を取得するバナー上に位置するムービー クリップを正常に作成します。onMouseDown 関数は、適切なバナーに移動するために、目的のバナー番号を渡す必要があります。それが理にかなっていることを願っています。
コードは次のとおりです。
import mx.transitions.Tween;
import mx.transitions.easing.*;
stop();
// Load data
var Articles:Array;
var Data:XML = new XML();
Data.ignoreWhite = true;
Data.onLoad = function(success:Boolean):Void
{
if (success)
{
var ArticleCount:Number = Data.firstChild.childNodes.length;
_global.maxDepth = ArticleCount * 2; //max depth that an Mc can be...
// homepage .article .image .value
//trace(Data.firstChild.childNodes[0].childNodes[1].firstChild.toString());
//create Array
Articles = new Array();
//loop through the articles
for (i:Number = 0; i < ArticleCount; i++)
{
var Node:XMLNode = Data.firstChild.childNodes[i];
var Article:Object =
{
Duration : Node.childNodes[0].firstChild.nodeValue,
BannerImage : Node.childNodes[1].firstChild.nodeValue,
Blurb : Node.childNodes[2].firstChild.nodeValue,
Link : Node.childNodes[3].firstChild.nodeValue
};
Articles.push(Article);
creaBottone(i);
}//end of 'for'
playAnimation(Articles);
}//end of 'if'
};
//Data.load(xmlpath);
Data.load("Homepage.xml");
function playAnimation(articlesArr:Array)
{
_global.mcArray = new Array();
_global.totalArticles = articlesArr.length;
_global.durationArray = new Array();
_global.linkArray = new Array();
var tweenTime:Number = 2; //time in seconds for an article to fade in/out
var globeDuration:Number = 3000; //milliseconds
var currDepth:Number = _global.maxDepth;
for(var i:Number = 0; i < articlesArr.length; i++)
{
var mc = bannerCont.attachMovie("article_mc", "article"+i, currDepth);
mc.gotoAndStop(1);
linkArray[i] = articlesArr[i].Link;
mc.imgCont._alpha = 100;
var imgRef = mc.imgCont.createEmptyMovieClip("img", 100);
var myListener = new Object();
var loader:MovieClipLoader = new MovieClipLoader();
myListener.mc = mc;
myListener.onLoadInit = function () {
var aScale:Tween = new Tween(this.mc.imgCont, "_alpha", Strong.easeIn, 0, 100, .5, true);
};
loader.addListener(myListener);
loader.loadClip(articlesArr[i].BannerImage, imgRef);
mc.blurbField.text = articlesArr[i].Blurb;
mcArray[i] = mc;
durationArray[i] = articlesArr[i].Duration;
currDepth -= 2;
}
var globe_mc = bannerCont.attachMovie("globeMc", "globe", _global.maxDepth + 1);
globe_mc._x = Stage.width/2;
globe_mc._y = Stage.height/2;
playGlobe(globe_mc);
_global.currArticleIndex = 0;
var curr:Number = _global.currArticleIndex;
setTimeout(showArticle, globeDuration, mcArray[0], tweenTime, (durationArray[0] * 1000), curr);
}
function showArticle(article:MovieClip, tweenTime, duration, currArticleIndex)
{
//trace("global:"+_global.linkArray[currArticleIndex]);
_root["urlText"] = _global.linkArray[currArticleIndex];
if(_global.linkArray[currArticleIndex] != null)
_root.btn.enabled = true;
article.gotoAndPlay(1);
article.linkBtn.enabled = true;
var globeDuration:Number = 3000;
var totalDuration:Number = duration;// + globeDuration;
trace(totalDuration);
setTimeout(fadeArticle, totalDuration, article, tweenTime, currArticleIndex);
}
function fadeArticle(article:MovieClip, tweenTime, currArticleIndex)
{
_root.btn.enabled = false;
var aScale:Tween = new Tween(article , "_alpha", Strong.easeIn, 100, 0, tweenTime, true);
var depth:Number = article.getDepth();
var globeMc = loadGlobe(depth);
aScale.onMotionFinished = function()
{
playGlobe(globeMc);
currArticleIndex += 1;
//if the currArticleIndex falls outside the article array boundaries
if(currArticleIndex >= _global.totalArticles)
{
currArticleIndex = 0;
var thisMc = bannerCont["article"+0];
var aScale:Tween = new Tween(thisMc , "_alpha", Strong.easeIn, 0, 100, tweenTime, true);
aScale.onMotionFinished = function(){
resetAlphas(_global.mcArray); //bring all the mc's alpha levels back to 100
}
}
var mc = _global.mcArray[currArticleIndex];
var duration:Number = parseInt(_global.durationArray[currArticleIndex]) * 1000;
setTimeout(showArticle, 3000, mc, tweenTime, duration, currArticleIndex);
}
}
function loadGlobe(depth:Number):MovieClip
{
var globe_mc = bannerCont.attachMovie("globeMc", "globe", depth-1);
globe_mc._x = Stage.width/2;
globe_mc._y = Stage.height/2;
globe_mc.gotoAndStop(1);
return globe_mc;
}
function playGlobe(globe_mc:MovieClip)
{
globe_mc.gotoAndPlay(1);
}
function resetAlphas(array:Array)
{
for(var i:Number = 0; i < array.length; i++)
{
var mc = bannerCont["article"+i];
mc._alpha = 100;
}
}
function getNextArticle(mcArray:Array, currIndex:Number)
{
var depth:Number = _global.maxDepth - ((currIndex+1)*2);
var mc = bannerCont.attachMovie("article_mc", "article"+(currIndex+1), depth);
mc.blurbField.text = mcArray[currIndex+1].blurbField.text;
//trace("here:"+mc.blurbField.text);
}
function creaBottone(currIndex:Number):Void
{
mymcn = eval("container"+currIndex);
var mymc:MovieClip = this.createEmptyMovieClip(mymcn, this.getNextHighestDepth()+currIndex);
var positionx = 30 + (currIndex * 30);
var positiony = (Stage.height - 35);
mymln = eval("label"+currIndex);
var myml:TextField = mymc.createTextField(mymln, 1, positionx, positiony, 20, 20);
myml.background = true;
myml.backgroundColor = 0xFFFFFF;
myml.text = String(currIndex+1);
myml.border = true;
f_myTxt = new TextFormat();
f_myTxt.align = 'center';
//f_myTxt.color = 0xDDDDDD;
myml.setTextFormat(f_myTxt);
mymc.onMouseDown = function() {
getNextArticle(_global.mcArray, currIndex);
}
}