hi. I’m a newbie in actionscripting. And I’m trying to make a sort of menu for each item in a carousel. I need to load in xml attributes to my dynamic text inside my duplicated movieclip. My duplicated movieclip is in the second code below.
I have two main AS in my .fla. This is my first code:
//SCRIPTS
Stage.align = "left";
num = 1;
total = 0;//total numofitems
rot = 0.5001 *Math.PI;
sliding = false;
rotGoto = rot;
rotTweening = rot;
rotImageNumber = 0;//who is on
autoRotate = false;
//import libs
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.display.BitmapData;
intThumb._visible = true;
diz = this;
// xml object / ignorewhite
xml = new XML();
xml.ignoreWhite = true;
//load object for parsing
xml.onLoad = function(sucess) {
if (sucess) {
storeAll(xml);
}
};
// load XML
if(_root.xmlLocation != undefined){
xml.load(_root.xmlLocation);
}else{
xml.load("data.xml");
}
// parsing function
function storeAll(xmlDoc_xml) {
//parse settings
for (at in xmlDoc_xml.childNodes[0].attributes) {
diz[at] = int(xmlDoc_xml.childNodes[0].attributes[at]*100)/100;
}
timer = autoRotateSpeed*24;
if (useFocalBlur == "1") {
useFocalBlur = true;
} else {
useFocalBlur = false;
}
if (useMotionBlur == "1") {
useMotionBlur = true;
} else {
useMotionBlur = false;
}
if (useReflection == "1") {
useReflection = true;
} else {
useReflection = false;
}
if (useFadeOnMouseOver == "1") {
useFadeOnMouseOver = true;
} else {
useFadeOnMouseOver = false;
}
//parse all imgs
for (var n = 0; n<xmlDoc_xml.childNodes[1].childNodes.length; n++) {
//add to folders list
duplicateMovieClip(intThumb, "thumb"+n, this.getNextHighestDepth());
thumbRef = this["thumb"+n];
thumbRef._visible = true;
thumbRef.num = n;
thumbRef.urls = xmlDoc_xml.childNodes[1].childNodes[n].attributes.imageURL;
thumbRef.linkData = xmlDoc_xml.childNodes[1].childNodes[n].attributes.linkData;
thumbRef.linkType = xmlDoc_xml.childNodes[1].childNodes[n].attributes.linkType;
thumbRef.linkTarget = xmlDoc_xml.childNodes[1].childNodes[n].attributes.linkTarget;
thumbRef.captionText = xmlDoc_xml.childNodes[1].childNodes[n].attributes.captionText;
thumbRef.captionText2 = xmlDoc_xml.childNodes[1].childNodes[n].attributes.captionText2;
//trace(thumbRef.menuText);
if(xmlDoc_xml.childNodes[1].childNodes[n].attributes.enableButtonWhenInFront == "1"){
thumbRef.enableButtonWhenInFront = true;
}else{
thumbRef.enableButtonWhenInFront = false;
}
loadMovie(thumbRef.urls, thumbRef.loader);
total += 1;
}
//end for folders
perinstance = (2*Math.PI)/total;
btns.swapDepths(30001);
navbar_bg.swapDepths(30000);
}
//end function
this.onEnterFrame = function() {
//timer for autorotate
if(autoRotateSpeed != undefined && autoRotate){
timer -= 1;
if (timer<0) {
rotImageNumber -= 1;
if (rotImageNumber<0) {
rotImageNumber = total-1;
}
rotGoto += perinstance;
timer = 24*autoRotateSpeed; //24 frames per second
}
}
//
if (rotationKind == 0) {
btns._visible = false;
rot -= (Stage.width/2-_xmouse)/10000*turningspeed;
} else {
btns._visible = true;
if (rotGoto != rotTweening) {
dist = Math.abs(rotGoto-rot);
if (dist>Math.PI) {
if (rotGoto>rot) {
rot += 2*Math.PI;
} else {
rot -= 2*Math.PI;
}
}
rotTweening = rotGoto;
var rottween:Tween = new Tween(this, "rot", Strong.easeInOut, rot, rotGoto, 4/turningspeed, true);
}
}
//subtitle
if(useSubtitle){
btns.subtitle.text = this["thumb"+rotImageNumber].captionText;
if(useSecondCaption){
btns.subtitle2.text = this["thumb"+rotImageNumber].captionText2;
}else{
btns.subtitle2.text = ""
}
}else{
btns.subtitle.text = ""
btns.subtitle2.text = ""
}
};
//buttons left and right
btns.btnLeft.onPress = function() {
rotImageNumber += 1;
if (rotImageNumber>=total) {
rotImageNumber = 0;
}
rotGoto -= perinstance;
};
btns.btnRight.onPress = function() {
rotImageNumber -= 1;
if (rotImageNumber<0) {
rotImageNumber = total-1;
}
rotGoto += perinstance;
};
//functions
function getX(number) {
ax = centerX+(1-distanceValue)*spanX*(Math.cos(rot+number*perinstance))*(perspectiveRatio+(1-perspectiveRatio)*(Math.sin(rot+number*perinstance)+1)/2);
return ax;
}
function getY(number) {
//ay = centerY+(1-distanceValue)*spanY*Math.sin(rot+number*perinstance);
ay = centerY+(1-distanceValue)*spanY*(Math.sin(rot+number*perinstance))*(perspectiveRatio+(1-perspectiveRatio)*(Math.sin(rot+number*perinstance)+1)/2);
return ay;
}
function getScale(number) {
sc = (minimumscale+(1-minimumscale)*(1+(Math.sin(rot+number*perinstance)))/2)*100;
sc *= 1-distanceValue;
return sc;
}
function blur(dis, number) {
if (useFocalBlur) {
fb = 15*focalBlurValue;
f = 20*distanceValue+fb-fb*(1+(Math.sin(rot+number*perinstance)))/2;
var blur = new flash.filters.BlurFilter(f, f, 1);
minf = -50;
darkness = -200*distanceValue+minf+Math.round((1+(Math.sin(rot+number*perinstance)))/(-2/minf));
var coma = [1, 0, 0, 0, darkness, 0, 1, 0, 0, darkness, 0, 0, 1, 0, darkness, 0, 0, 0, 1, 0];
var brightness = new flash.filters.ColorMatrixFilter(coma);
var tmpFilters:Array = dis.filters;
tmpFilters.push(blur);
tmpFilters.push(brightness);
dis.filters = tmpFilters;
}
}
function motionBlur(dis, xdist, ydist) {
if (useMotionBlur) {
var blur = new flash.filters.BlurFilter(xdist*motionBlurValue, ydist*motionBlurValue, 1);
var tmpFilters:Array = dis.filters;
tmpFilters.push(blur);
dis.filters = tmpFilters;
}
}
function reflect(src, target, alpha, wi, he) {
var bdata:BitmapData = new BitmapData(wi/(src._xscale/100), he/(src._yscale/100), true, 0x00ffffff);
bdata.draw(src);
var refmc:MovieClip = target.createEmptyMovieClip("refmc", 0);
refmc.attachBitmap(bdata,0);
refmc._width = wi;
refmc._height = he;
refmc._yscale = -refmc._yscale;
refmc._y = he;
var rmask = target.createEmptyMovieClip("rmask", 1);
var matrix = {matrixType:"box", x:0, y:0, w:wi, h:he, r:(90/180)*Math.PI};
rmask.beginGradientFill("linear",[0xffffff, 0xffffff],[alpha, 0],[0, 100],matrix,"pad");
rmask.moveTo(0,0);
rmask.lineTo(0,he);
rmask.lineTo(wi,he);
rmask.lineTo(wi,0);
rmask.lineTo(0,0);
rmask.endFill();
refmc.cacheAsBitmap = true;
rmask.cacheAsBitmap = true;
refmc.setMask(rmask);
}
And my second code is this with the duplicated movieclipCOLOR=#bf8040[/COLOR]. I need the duplicated movieclip to contain dynamic text, the text being loaded from my xml file.
the hierarchy of my movieclip with the dynamic text is this> _parent.btns.intNavbar.label_mc.buttText.text
how can i link this to my xml file? how do i load xmlDoc_xml.childNodes[1].childNodes[n].attributes.menuText; to my dynamic text? where do i declare this line of code?
over = false;
reflected = false;
alphatweened = false;
alphaTo = 0;
if (num == undefined) {
_visible = false;
}
//navbar
duplicateMovieClip(_parent.btns.intNavbar, "nav"+num, _parent.btns.getNextHighestDepth());
navRef = _parent.btns["nav"+num];
navRef._visible = true;
navRef.num = num;
navRef._y = _parent.btns.navbar_bg._y+(_parent.btns.navbar_bg._height/(_parent.total-1))*(_parent.total-num);
if (num == 0) {
navRef._y = _parent.btns.navbar_bg._y;
}
navRef._x = _parent.btns.navbar_bg._x;
this.onEnterFrame = function() {
if (_parent.rotationKind == 1) {
if (!enableButtonWhenInFront && num == _parent.rotImageNumber) {
//loader in front of button
loader.swapDepths(-16378);
button.useHandCursor = false;
} else {
//loader behind button
loader.swapDepths(-16380);
button.useHandCursor = true;
}
}
if (_parent.rotationKind == 0) {
if (!enableButtonWhenInFront) {
//loader in front of button
loader.swapDepths(-16378);
button.useHandCursor = false;
} else {
//loader behind button
loader.swapDepths(-16380);
button.useHandCursor = true;
}
}
//tween fading
if (alphatweened == false && _parent.overNumber != num && _parent.overNumber != "" && _parent.useFadeOnMouseOver) {
alphatweened = true;
alphaTo = _parent.mouseOverAlphaValue*100;
}
if (alphatweened == true && (_parent.overNumber == num || _parent.overNumber == "") && _parent.useFadeOnMouseOver && reflected) {
alphatweened = false;
alphaTo = 100;
}
loader._alpha += (alphaTo-loader._alpha)/10;
reflection._alpha += (alphaTo-reflection._alpha)/10;
sy = _parent.spanY*4;
if (sy<0) {
sy = 0;
}
if (sy>loader._height) {
sy = loader._height;
}
if (reflected) {
reflection._height = sy;
}
//preload
ldd = loader.getBytesLoaded();
ttl = loader.getBytesTotal();
if (loader._url != this._url && ldd != ttl) {
preloader._visible = true;
preloader.gotoAndStop(Math.round((ldd/ttl*100)/16.67));
//loader._visible = false;
} else {
if (reflected == false && loader._url != this._url) {
size();
reflected = true;
}
preloader._visible = false;
}
if (this._name != "intThumb" /*&& reflected*/) {
_x = _parent.getX(num);
_y = _parent.getY(num);
sc = _parent.getScale(num);
_xscale = sc;
_yscale = sc;
while (_parent.getInstanceAtDepth(Math.round(sc)) != undefined) {
sc += 1;
}
this.swapDepths(Math.round(sc*100));
this.filters = "";
_parent.blur(this,num);
_parent.motionBlur(this,Math.abs(_x-prevx),Math.abs(_y-prevy));
}
prevx = _x;
prevy = _y;
if (myReflectionValue != _parent.reflectionAlphaValue && reflected) {
reflected = false;
size();
}
};
function size() {
loader._visible = true;
//resize
loader._xscale = 100;
loader._yscale = 100;
loader._x = -loader._width/2;
loader._y = -loader._height;
button._width = loader._width;
button._height = loader._height;
button._y = loader._y;
button._x = loader._x;
mmask._width = loader._width;
mmask._height = loader._height;
mmask._y = loader._y;
mmask._x = loader._x;
reflection._x = loader._x;
reflection._y = loader._y+loader._height;
if (_parent.useReflection) {
myReflectionValue = _parent.reflectionAlphaValue;
_parent.reflect(loader,reflection,_parent.reflectionAlphaValue*100,loader._width,loader._height);
}
alphaTo = 100;
}
Hope anyone could lend a helping hand. Thanks in advance.