我有一个flash电影,它会拉入xml并在循环中吐出横幅。但是,我需要通过在横幅上设置一个按钮列表来提供轮播样式功能,这些按钮提供了一个“转到”的按钮。横幅链接,即1 2 3 4 5等。
我可以创建一个影片剪辑,因为它循环遍历xml以创建goto链接,但它是我遇到问题的Click功能。基本上是针对新创建的影片剪辑按钮。
函数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);
}
}
答案 0 :(得分:0)
试试这段代码:
mymc.currIndex = currIndex;
mymc.onMouseDown = function()
{
getNextArticle(_global.mcArray, this.currIndex);
}