开发者

Flash Actionscript With XML has trouble loading onClick

http://soulseekrecords.org/psysci/animation/tarot.html

If you go to that page and click the deck of cards. Some clicks don't work. Most clicks do. This onclick problem also happens when testing the movie in flash.

//import tweening files
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import fl.controls.UIScrollBar;
import flash.display.Sprite;


//create array of image names
var imageNames:Array = new Array();
var descText:Array = new Array();

//variable for total number of images
var totalImages:uint = imageNames.length;

//create a variable to load the large image
var bigImageLoader:Loader = new Loader;
//add bigImageLoader to the display list

//create random number
var randomNumber:uint;

//Scroll Variables
var scrollBarAdd:Boolean = false;
var scrollBar:UIScrollBar = new UIScrollBar();

addChild(bigImageLoader);
bigImageLoader.x = 130;
bigImageLoader.y = 25;

//create a textField
var myText:TextField = new TextField();

//add text box to display list
addChild(myText);
myText.width = 400;
myText.height = 180;
myText.x = 20;
myText.y = 200;
myText.wordWrap = true;
myText.multiline = true;
myText.selectable = true;

var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.color = 0x000000;
format.size = 16;
format.underline = false;

myText.defaultTextFormat = format;

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("master.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event)
{
myXML = new XML (e.target.data);
for(var i:uint = 0; i < myXML.img.length() ; i++)
{
imageNames.push(myXML.img[i].text());
descText.push(myXML.txt[i].text()) ; 
}
totalImages = imageNames.length;
}
//add button
var deckOfCards:Deck = new Deck();

//add button to display list
addChild(deckOfCards);


//Set button x and y position
deckOfCards.x = 20;
deckOfCards.y = 20;

//set buttonmode
deckOfCards.buttonMode = true;

//make sure all clicks register with the thumb itself (not inner contents)
deckOfCards.mouseChildren = false;

//add click listener to the button
deckOfCards.addEventListener(MouseEvent.MOUSE_DOWN, buttonClickHandler);

function buttonClickHandler (event:MouseEvent)
{

for ( var i:uint = 0; i < totalImages; i++ )
{
randomNumber = Math.round(Math.random()*totalImages);

if (randomNumber == i)
{
//load the corect image into the big image loader
bigImageLoader.load(new URLRequest("images/" + imageNames[randomNumber] ) );
bigImageLoader.scaleX = .0;
TweenLite.to( bigImageLoader, .5, {scaleX:1 , ease:Expo.easeOut} );
myText.alpha = 0;
TweenLite.to( myText, .5, {alpha:1} );
myText.text = String (descText[randomNumber]);

if (myText.textHeight > myText.height)
{
scrollBar.scrollTarget = myText;  //assign the target of the scrollBar to your textfield
scrollBar.height = myText.height;  //make the height the same as the textfield
scrollBar.move(myText.x + myText.width, myText.y);  //Move the scrollbar to the righthand side
addChild(scrollBar);
scrollBar.update();
scrollBarAdd = true;
} else { 
if((myText.textHeight < myText.height) && scrollBarAdd == true){
scrollBarAdd = false;
removeChild(scrollBar);
}
}
}
}
}

my xml is structured like this

<?xml version="1.0" encoding="UTF-8"?>
<master>
<开发者_如何学Python;img>joker.png</img>
<img>aceOfClubs.png</img>
<img>twoOfClubs.png</img>
...


<txt>The average stage of man...</txt>
<txt>This is an Ace of Clubs.</txt>
<txt>This is a two of Clubs.</txt>
...
</master>


You may have done this already, but to discern if its the actually event or your code which is creating this problem, stick a trace in the buttonClickHandler before you do your loop.

I'm interested in if the event is actually firing when you click that deck...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜