trace the name of the day when clicking on calendar - actionscript-3

I've downloaded a free code for a calendar that I've modified a little bit.
Currently, when I click on a square on the calendar, the "trace" tells me the date like "19 november 2015".
I would like to be able to trace the day of the week too. (like Thursday 19 novembre 2015).
Here's my code :
if(nM == 0){
var nM:int = 0;
}
var monthsOfYear:Array = new Array("Janvier", "February", "March", "April", "May", "June", "July", "August", "September", "October", "novembre", "decembre");
var daysOfMonths:Array = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var addMonths:int = (currentDate.getMonth()+nM);
var myDate = new Date(currentDate.getFullYear(), currentDate.getMonth()+nM);//provided by Andrei Firoiu
var startDay = myDate.getDay();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void{
calendar.month_txt.text = monthsOfYear[addMonths];
calendar.year_txt.text = " " + myDate.fullYear;
}
while (addMonths > 11)
{
addMonths = addMonths - 12;
}
while (addMonths < 0)
{
addMonths = addMonths + 12;
}
calendar.lM_mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseClickEvent1);
function onMouseClickEvent1(event:Event){
nM = nM-1;
removeChild(holder_txt);
play();
calendar.month_txt.text = monthsOfYear[addMonths];
calendar.year_txt.text = " " + myDate.fullYear;
}
calendar.nM_mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseClickEvent);
function onMouseClickEvent(event:Event){
nM = nM+1
removeChild(holder_txt);
play();
calendar.month_txt.text = monthsOfYear[addMonths];
calendar.year_txt.text = " " + myDate.fullYear;
}
function getDays(date:Date):uint {
return (myDate.getFullYear()%4 == 0 && myDate.getMonth() == 1 ? 29 : daysOfMonths[myDate.getMonth()]);
}
//-----------------------------
var myArray:Array = new Array();
//var spacing:int = 50;
var row:Number = 0;
var holder_txt:MovieClip = new MovieClip;
addChild(holder_txt);
holder_txt.x = 35;
holder_txt.y = 10;
//addChild(squares);
for (var t:int = 0; t < getDays(myDate); t++) {
myArray[t] = (t+1);
var textNum:String = myArray[t];
import box;
var square:MovieClip = new box();
holder_txt.addChild(square);
square.name = textNum
square.texter.text = textNum;
square.x = startDay *75
square.y = (row+1)*65
startDay++;
if(startDay >= 7){
startDay = 0;
row++;
}
square.mouseChildren = false;
square.addEventListener(MouseEvent.CLICK, squareClicked);
//square.addEventListener(MouseEvent.MOUSE_OVER, tab1Over);
square.addEventListener(MouseEvent.MOUSE_OUT, tab1Out);
//square.addEventListener(MouseEvent.MOUSE_DOWN,tab1Down);
//function tab1Over (e:Event):void{
// e.currentTarget.play();
// trace(e.currentTarget.name +" "+ monthsOfYear[addMonths]+" "+myDate.fullYear);
// }
function squareClicked (e:Event):void{
e.currentTarget.play();
trace(e.currentTarget.name +" "+ monthsOfYear[addMonths]+" "+myDate.fullYear);
mySharedObject.data.theDate = e.currentTarget.name +" "+ monthsOfYear[addMonths]+" "+myDate.fullYear;
trace(mySharedObject.data.theDate);
mySharedObject.data.theCity = "Noumea";
}
function tab1Out (e:Event):void{
e.currentTarget.gotoAndStop(1);}
}
Thx for your help,

This is very often asked and search should show many answers for it. But, you can use getDay():
var weekDayLabels:Array = new Array("Sunday","Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday");
var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday); // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getDay()); // 6
trace(weekDayLabels[someBirthday.getDay()]); // Saturday

Related

"is MovieClip" is true, yet compiler insists it is not and throws Error #1034: Type Coercion failed? (AS3)

I have in my library, various food icons converted and linked as MovieClips which i add to the scene dynamically. I'm trying to move them from one container to another. Containers are also dynamically added MovieClips.
I've been trying to move these icons who are "MovieClip extended class" instances to another MovieClip as child, by drag and drop, yet currentTarget in drop(it is fine in drag) is not recognised as MovieClip even with "currentTarget as MovieClip" and compiler throws error. Every trace indicates that it is indeed a MovieClip though. I'm at my wits end.
The "plate.addChild(mc);" is causing the error during dropping into the "plate" from "shelves".
The .fla file: https://1drv.ms/u/s!ApqQOqYhGvWHget1A4YRqyzT3a9BEQ?e=9UJB0R
import flash.display.Sprite;
import flash.display.MovieClip;
/*;
choValues = {
"apple": 15,
"bakedBeans": 15,
"chickenLeg": 0,
"chickenNuggets": 15,
"cornOnTheCob": 15,
"egg": 0,
"grapes": 5,
"hamburger": 30,
"milkFull": 24,
"juiceFull": 30,
"juiceHalf": 15,
"saltineCrackers": 5,
"orange": 15,
"tomato": 5
}*/
var foodNames:Array = new Array();
var choValues:Array = new Array();
var options:Array = new Array();
var index:Array = new Array();
var shelves:MovieClip = new Shelves();
var plate:MovieClip = new Plate();
var plateSlots:Array = [0,0,0,0];
var iconSize:Array = new Array();
trace(stage.stageWidth);
trace(stage.stageHeight);
var relativeWidth:Number = stage.stageWidth/32;
var relativeHeight:Number = stage.stageHeight/32;
trace("shelves");
trace(shelves.x = relativeWidth*4 );
trace(shelves.y = relativeHeight*8);
trace(shelves.width = relativeWidth*10);
trace(shelves.height = relativeHeight*14);
stage.addChildAt(shelves,1);
trace("plate");
plate.instanceName = "plate";
trace(plate.x = relativeWidth*15 );
trace(plate.y = relativeHeight*8);
trace(plate.width = relativeWidth*10);
trace(plate.height = relativeHeight*14);
plate.name = "plate";
stage.addChildAt(plate,0);
trace("plate.name "+ plate.name);
/*var fruit = new orange;
trace("fruit");
trace(fruit.x = plate.width/2);
trace(fruit.y = plate.height/2);
//trace(plateSlots.width = plate.width/2);
//trace(plateSlots.height = plate.height/2);*/
//plate.addChild(fruit);
function drag (e:MouseEvent):void //find the slot
{
e.currentTarget.startDrag();
trace("drag "+e.currentTarget.name);
trace("Classname "+ getQualifiedClassName(e.currentTarget));
}
function drop (e:MouseEvent):void
{
e.currentTarget.stopDrag();
trace("drop Classname "+ getQualifiedClassName(e.currentTarget));
trace("drop name "+ (e.currentTarget.name));
//if(e.currentTarget.dropTarget !=null)
//if(e.currentTarget.dropTarget.parent !=null)
//if(e.currentTarget.dropTarget.parent.parent != null)
try{if (e.currentTarget.dropTarget.parent.parent.name == "plate")
{
trace("currentTarget is "+e.currentTarget);
var mc:MovieClip = MovieClip(e.currentTarget);
trace(mc);
trace("mc is movieClip?" + (mc is MovieClip));
trace("is plate");
for (var i=0; i<4; i++)
{
if (plateSlots[i] == 0)
{
trace(mc);
//shelves.removeChild(mc);
plate.addChild(mc);
//e.currentTarget.width = iconSize[0];
//e.currentTarget.height = iconSize[1];
trace(mc.x = plate.width/6 + ((i%2)*plate.width/8));
trace(mc.y = plate.height/6 + ((i<2 ? 0:1)*plate.height/4));
plateSlots[i] = 1;
mc.slot = i;
return;
}
}
}
else{
shelves.addChild(e.currentTarget as MovieClip);
e.currentTarget.x = e.currentTarget.oldX;
e.currentTarget.y = e.currentTarget.oldY;
}
}
catch(e:Error){}
shelves.addChild(e.currentTarget as MovieClip);
e.currentTarget.x = e.currentTarget.oldX;
e.currentTarget.y = e.currentTarget.oldY;
}
function randomize ( a : *, b : * ) : int {
return ( Math.random() > .5 ) ? 1 : -1;
}
foodNames.push(
"apple","bakedBeans","chickenLeg",
"chickenNuggets","cornOnTheCob","egg",
"grapes","hamburger","milkFull",
"juiceFull","juiceHalf","saltineCrackers",
"orange","tomato"
)
choValues.push(
15,15,0,
15,15,0,
5,30,24,
30,15,5,
15,5
)
for (var i:int=1; i<foodNames.length; i++)
{
index.push(i);
}
index.sort(randomize);
trace(index);
for(i=0; i<8; i++)
{
options[index[i]] = new (getDefinitionByName(foodNames[index[i]]));
trace("class "+getDefinitionByName(foodNames[index[i]]));
options[index[i]].addEventListener(MouseEvent.MOUSE_DOWN, drag);
options[index[i]].addEventListener(MouseEvent.MOUSE_UP, drop);
options[index[i]].CHO = choValues[i];
options[index[i]].x += ( (2*(i%4)) +1 ) *(shelves.width /10);
options[index[i]].y = ( ( i<4 ) ? 17 : 37 )*(shelves.height/64);
options[index[i]].oldX = options[index[i]].x;
options[index[i]].oldY = options[index[i]].y;
shelves.addChild(options[index[i]]);
}
//iconSize[0] = options[index[0]].width;
//iconSize[1] = options[index[0]].height;
stop();

Get points in selected are in the teechart

Trying to get series values in the selected area after mouseup.
Need to calculate width and height of the selected are in the chart with respect to axis.
[`https://jsbin.com/wapovohiwe/edit?html,output`][1]
I modified your example to draw the rectangle and to output the coordinates of the
Chart1 = new Tee.Chart("canvas");
Chart1.legend.visible = false;
Chart1.panel.format.gradient.visible = false;
Chart1.panel.format.fill = "white";
Chart1.walls.back.format.fill = "white";
Chart1.addSeries(new Tee.Line([1, 3, 0, 2, 7, 5, 6]));
Chart1.zoom.enabled = false;
var myFormat = new Tee.Format(Chart1);
myFormat.transparency = 0.9;
var rect = {},
drag = false;
Chart1.mousedown = function(e) {
rect.startX = e.x - canvas.offsetLeft - canvas.parentElement.offsetLeft - canvas.parentElement.parentElement.offsetLeft;
rect.startY = e.y - canvas.offsetTop - canvas.parentElement.offsetTop - canvas.parentElement.parentElement.offsetTop;
drag = true;
}
Chart1.mouseup = function(p) {
var i, tmpP = {};
points = [];
var s = Chart1.series.items[0];
for (i = 0; i < s.count(); i++) {
s.calc(i, tmpP);
if ((tmpP.x >= rect.startX) && (tmpP.x <= rect.startX + rect.w) && (tmpP.y >= rect.startY) && (tmpP.y <= rect.startY + rect.h))
console.log("index: " + i + ", value: " + s.data.values[i]);
}
drag = false;
}
Chart1.mousemove = function(e) {
if (drag) {
rect.w = e.x - rect.startX;
rect.h = e.y - rect.startY;
drawChart();
}
}
function drawChart() {
Chart1.draw();
myFormat.rectangle(rect.startX, rect.startY, rect.w, rect.h);
}
Chart1.draw();
<script src="https://www.steema.com/files/public/teechart/html5/latest/src/teechart.js"></script>
<canvas id="canvas" height="400" width="700"></canvas>

How do I remove eventlisteners and objects from an array upon game completion?

I have written a drag and drop game and, for the most part, it works.
It runs and does what I need it to do.
However, I cannot figure out two things.
How to remove the toy objects from the screen and re-add them after game over.
How to remove the event listeners for dragging/collision action after game over has initiated.
At the moment, after score is displayed you can still drop items in the toybox and make the score rise even when game over has been displayed.
Does anyone have any idea what I am doing wrong?
I would love to figure this out but it is driving me crazy.
Any help would be great.
Here is my code ...
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.Font;
import flash.filters.GlowFilter;
public class MainGame extends MovieClip {
const BG_SPEED:int = 5;
const BG_MIN:int = -550;
const BG_MAX:int = 0;
const PBG_SPEED:int = 3;
var bg:BackGround = new BackGround;
var paraBg:ParaBg = new ParaBg;
var toybox:TargetBox = new TargetBox;
var toy:Toy = new Toy;
var tryAgain:TryAgain = new TryAgain;
var cheer:Cheer = new Cheer;
var eightBit:EightBit = new EightBit;
var countDown:Number = 30;
var myTimer:Timer = new Timer(1000, 30);
var myText:TextField = new TextField;
var myText2:TextField = new TextField;
var myTextFormat:TextFormat = new TextFormat;
var myTextFormat2:TextFormat = new TextFormat;
var font1:Font1 = new Font1;
var kids:Kids = new Kids;
var count:int = 0;
var finalScore:int = 0;
var score:Number = 0;
var toy1:Toy1 = new Toy1;
var toy2:Toy2 = new Toy2;
var toy3:Toy3 = new Toy3;
var toy4:Toy4 = new Toy4;
var toy5:Toy5 = new Toy5;
var toy6:Toy6 = new Toy6;
var toy7:Toy7 = new Toy7;
var toy8:Toy8 = new Toy8;
var toy9:Toy9 = new Toy9;
var toy10:Toy10 = new Toy10;
var toy11:Toy11 = new Toy11;
var toy12:Toy12 = new Toy12;
var toy13:Toy13 = new Toy13;
var toy14:Toy14 = new Toy14;
var toy15:Toy15 = new Toy15;
var toy16:Toy16 = new Toy16;
var toy17:Toy17 = new Toy17;
var toy18:Toy18 = new Toy18;
var toy19:Toy19 = new Toy19;
var toy20:Toy20 = new Toy20;
var toyArray:Array = new Array(toy1, toy2, toy3, toy4, toy5, toy6, toy7, toy8, toy9, toy10, toy11, toy12, toy13, toy14, toy15, toy16, toy17, toy18, toy19, toy20);
public function mainGame():void
{
trace("HI");
eightBit.play(0, 9999);
addChildAt(paraBg, 0);
addChildAt(bg, 1);
addChildAt(kids, 2);
kids.x = 310;
kids.y = 200;
addChild(toy);
toy.x = 306;
toy.y = 133;
addChild(toybox);
toybox.x = 295;
toybox.y = 90;
function addToys(xpos:int, ypos:int)
{
addChild(toyArray[i]);
toyArray[i].x = xpos;
toyArray[i].y = ypos;
}
for (var i:int = 0; i < toyArray.length; i++)
{
addToys(1140 * Math.random() + 20, 170 * Math.random() + 230);
}
}
public function bgScroll (e:Event)
{
stage.addEventListener(MouseEvent.MOUSE_UP, arrayDrop);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerDone);
myTimer.start();
e.target.addEventListener(Event.ENTER_FRAME, collision);
if (stage.mouseX > 600 && bg.x > BG_MIN)
{
bg.x -= BG_SPEED;
paraBg.x -= PBG_SPEED;
for (var m:int=0; m< toyArray.length; m++)
{
(toyArray[m] as MovieClip).x -=BG_SPEED
}
}
else if (stage.mouseX < 50 && bg.x < BG_MAX)
{
bg.x += BG_SPEED;
paraBg.x += PBG_SPEED;
for (var j:int=0; j< toyArray.length; j++)
{
(toyArray[j] as MovieClip).x +=BG_SPEED
}
}
for (var k:int = 0; k < toyArray.length; k++)
{
toyArray[k].addEventListener(MouseEvent.MOUSE_DOWN, arrayGrab);
}
bg.addEventListener(Event.ENTER_FRAME, bgScroll);
} // End of BGScroll
public function collision (e:Event)
{
for (var l:int=0; l< toyArray.length; l++)
{
if (toyArray[l].hitTestObject(toy))
{
removeChild(toyArray[l]);
toyArray[l].x=100000;
toybox.gotoAndPlay(2);
cheer.play(1, 1);
score = score + 10;
trace(score);
}
if (score == 200)
{
timerDone();
myTimer.stop();
}
}
}
public function arrayGrab(e:MouseEvent)
{
e.target.startDrag();
}
public function arrayDrop(e:MouseEvent)
{
stopDrag();
}
public function resetGame(e:Event):void {
trace("CLICK");
countDown = 30;
myText.text = "0" + countDown.toString();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerDone);
myTimer.reset();
removeChild(tryAgain);
myText2.visible = false;
score = 0;
}
public function countdown(e:TimerEvent):void
{
if (countDown > 0)
{
countDown--;
}
if (countDown < 10)
{
myText.text = "0" + countDown.toString();
myText.x = 270;
displayText();
}
else if (countDown < 20 && countDown > 9)
{
myText.text = countDown.toString();
myText.x = 280;
displayText();
}
else
{
myText.text = countDown.toString();
myText.x = 270;
displayText();
}
} // end of countdown function
public function displayText():void
{
myText.filters = [new GlowFilter(0x00FF00, 1.0, 5, 5, 4)];
addChild(myText);
myText.width = 500, myText.height = 50, myText.y = 10;
myTextFormat.size = 50, myTextFormat.font = font1.fontName;
myText.setTextFormat(myTextFormat);
}
public function displayText2():void
{ myText2.filters = [new GlowFilter(0xFF0000, 1.0, 5, 5, 4)];
addChild(myText2);
myText2.width = 500, myText2.height = 35, myText2.x = 204, myText2.y = 200;
myTextFormat2.size = 30, myTextFormat2.font = font1.fontName;
myText2.setTextFormat(myTextFormat2);
}
public function timerDone(e:TimerEvent=null):void
{
if (countDown == 0)
{
count = 0;
finalScore = score;
}
else
{
count = (30) - (myTimer.currentCount);
finalScore = (count * 10) + (score);
}
myText.text = "GAME OVER!";
myText.x = 195;
displayText();
myText2.text = "Your score = " + (finalScore);
displayText2();
addChild(tryAgain);
tryAgain.x = 300;
tryAgain.y = 300;
tryAgain.addEventListener(MouseEvent.CLICK, resetGame);
}
} // End of class
} //End of package
Nevermind ... solved it.
Easiest was was to change
function addToys(xpos:int, ypos:int)
{
addChild(toyArray[i]);
toyArray[i].x = xpos;
toyArray[i].y = ypos;
}
To
function addToys(xpos:int, ypos:int)
{
stage.addChild(toyArray[i]);
toyArray[i].x = xpos;
toyArray[i].y = ypos;
}
And then, in the timerDone function I added thisif statement ...
for (var m = 0; m < toyArray.length; m++) {
if (stage.contains(toyArray[m])) {
stage.removeChild(toyArray[m]);
}
Worked a treat!

Pass to the next image everyday

I'm developing a small app in AS3.
Everyday, you can see a new image.
I've got all my image on a server.
Here is my code for the moment :
var imageLoader:Loader = new Loader();
var days:Array = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
var my_date:Date = new Date();
trace(days[my_date.day]);
startBtn.addEventListener(MouseEvent.CLICK, LoadImage, false, 0, true);
function LoadImage(event:MouseEvent):void{
var image:URLRequest = new URLRequest ("http://www.blabla.com/images/12.jpg");
imageLoader.load(image);
addChild (imageLoader);
}
Is it possible to tell the code the go the next image (13.jpg) the next day ? and everyday like that (next day = 14.jpg , next day = 15.jpg....ect).
Do you know a way to do that ?
Thank you very much for your help,
The code below should do it. I grabbed the getDayOfYear function from here: siafoo.net
I will post some optimizations to the function in a little while.
function getDayOfYear(date:Date):Number {
var monthLengths:Array = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// A leap year is divisable by 4, but not by 100 unless divisable by 400.
if (((date.getFullYear() % 4 == 0) && (date.getFullYear() % 100 != 0)) || (date.getFullYear() % 400 == 0)) {
monthLengths[1] = 29;
}
var dayInYear = 0;
// get day of year up to month
for (var i:Number = 0; i < date.getMonth(); i++) {
dayInYear += monthLengths[i];
}
// add day inside month
dayInYear += date.getDate();
// Start counting on 0 (optional)
// dayInYear--;
return dayInYear;
}
function LoadImage(event:MouseEvent):void{
var image:URLRequest = new URLRequest ("http://www.blabla.com/images/"+getDayOfYear(new Date())+".jpg");
imageLoader.load(image);
addChild (imageLoader);
}

Problems with Wordwrap in Flashpunk

For some reason, the last line of my wordwrap does not display
public class ShopButton extends Entity
{
private var callback:Function = null;
public var buttonText:String = "";
public var textImage:Text;
public var picture:BitmapData = new BitmapData(100, 100, true, 1);
public var boxImage:Stamp;
public var displayImage:Graphiclist;
public var displayImage2:Graphiclist;
public var tooltipPicture:BitmapData = new BitmapData(150, 130, true, 1);
public var tooltipBox:Stamp;
public var tooltipText:Array = [];
public var tooltipString:Array = [];
public var buttonWidth:int = 100;
public var buttonHeight:int = 100;
private var clicked:Boolean = false;
private var shiftClicked:Boolean = false;
private var hovered:Boolean = false;
private var fontSize:int = 16;
public var label:String = "";
public function ShopButton(x:int = 0, y:int = 0, label:String = "", callback:Function = null)
{
this.callback = callback;
this.label = label;
buttonText = label;
textImage = new Text(buttonText, 5, 5, { width:buttonWidth-10, wordWrap:true, align:"center", size:fontSize, font:"Abscissa" } );
Draw.setTarget(picture);
Draw.rectPlus(0, 0, buttonWidth, buttonHeight, 0x000000, 1, true, 2, 5);
Draw.rectPlus(0, 0, buttonWidth, buttonHeight, 0xFFFF00, 1, false, 5, 5);
boxImage = new Stamp(Assets.SHOPBUTTON);
textImage.y = (boxImage.height / 2) - (textImage.height / 2);
displayImage = new Graphiclist(boxImage, textImage);
super (x, y, displayImage);
setHitboxTo(boxImage);
Draw.setTarget(tooltipPicture);
Draw.rectPlus(0, 0, 150, 130, 0x000000, 1, true, 1, 0);
Draw.rectPlus(0, 0, 150, 130, 0xFFFF00, 1, false, 5, 0);
tooltipBox = new Stamp(Assets.SHOPBUTTONBORDER);
updateTooltip();
}
public function updateTooltip():void
{
var minDamage:int = 0;
var maxDamage:int = 0;
var damageResist:int = 0;
switch(label)
{
case "Purchase Ammo":
tooltipString[0] = "";
tooltipString[1] = "Purchase more";
tooltipString[2] = "shurikens";
tooltipString[3] = "";
tooltipString[4] = "Shift + Click";
tooltipString[5] = "To buy max";
break;
case "Upgrade Melee Weapon":
minDamage = Globals.meleeDamage[0][Globals.meleeLevel];
maxDamage = Globals.meleeDamage[1][Globals.meleeLevel];
minDamage = minDamage * (1+(Globals.playerMeleeDamage / 100));
maxDamage = maxDamage * (1 + (Globals.playerMeleeDamage / 100));
tooltipString[0] = "Current Level";
tooltipString[1] = "Damage: "
tooltipString[2] = "" + minDamage + " - " + maxDamage;
tooltipString[3] = "Next Level";
if (Globals.meleeLevel < Globals.meleeMaxLevel)
{
minDamage = Globals.meleeDamage[0][Globals.meleeLevel + 1];
maxDamage = Globals.meleeDamage[1][Globals.meleeLevel + 1];
minDamage = minDamage * (1+(Globals.playerMeleeDamage / 100));
maxDamage = maxDamage * (1 + (Globals.playerMeleeDamage / 100));
tooltipString[4] = "Damage: "
tooltipString[5] = "" + minDamage + " - " + maxDamage;
}
else
{
tooltipString[4] = "";
tooltipString[5] = "Max Level";
}
break;
case "Upgrade Ranged Weapon":
minDamage = Globals.rangedDamage[0][Globals.rangedLevel];
maxDamage = Globals.rangedDamage[1][Globals.rangedLevel];
minDamage = minDamage * (1+(Globals.playerRangeDamage / 100));
maxDamage = maxDamage * (1 + (Globals.playerRangeDamage / 100));
tooltipString[0] = "Current Level";
tooltipString[1] = "Damage: "
tooltipString[2] = "" + minDamage + " - " + maxDamage;
tooltipString[3] = "Next Level";
if (Globals.rangedLevel < Globals.rangedMaxLevel)
{
minDamage = Globals.rangedDamage[0][Globals.rangedLevel + 1];
maxDamage = Globals.rangedDamage[1][Globals.rangedLevel + 1];
minDamage = minDamage * (1+(Globals.playerRangeDamage / 100));
maxDamage = maxDamage * (1 + (Globals.playerRangeDamage / 100));
tooltipString[4] = "Damage: "
tooltipString[5] = "" + minDamage + " - " + maxDamage;
}
else
{
tooltipString[4] = "";
tooltipString[5] = "Max Level";
}
break;
case "Upgrade Armor":
damageResist = Globals.armorDefense[Globals.armorLevel];
damageResist = damageResist * (1 + (Globals.playerDefense / 100));
tooltipString[0] = "Current Level";
tooltipString[1] = "Damage Resist: "
tooltipString[2] = "" + damageResist;
tooltipString[3] = "Next Level";
if (Globals.armorLevel < Globals.armorMaxLevel)
{
damageResist = Globals.armorDefense[Globals.armorLevel + 1];
damageResist = damageResist * ( 1 + (Globals.playerDefense / 100));
tooltipString[4] = "Damage Resist: "
tooltipString[5] = "" + damageResist;
}
else
{
tooltipString[4] = "";
tooltipString[5] = "Max Level";
}
break;
}
tooltipText[0] = new Text(tooltipString[0], 0, 10, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[0].x = -25;
tooltipText[0].y -= 20;
tooltipText[1] = new Text(tooltipString[1], 0, 30, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[1].x = -25;
tooltipText[1].y -= 20;
tooltipText[2] = new Text(tooltipString[2], 0, 45, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[2].x = -25;
tooltipText[2].y -= 20;
tooltipText[3] = new Text(tooltipString[3], 0, 65, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[3].x = -25;
tooltipText[3].y -= 20;
tooltipText[4] = new Text(tooltipString[4], 0, 85, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[4].x = -25;
tooltipText[4].y -= 20;
tooltipText[5] = new Text(tooltipString[5], 0, 100, {width:150, align:"center", size:fontSize, font:"Abscissa"});
tooltipText[5].x = -25;
tooltipText[5].y -= 20;
tooltipBox.x = -25;
tooltipBox.y = -20;
displayImage2 = new Graphiclist(tooltipBox, tooltipText[0], tooltipText[1], tooltipText[2], tooltipText[3], tooltipText[4], tooltipText[5]);
}
public function click(action:String = ""):void
{
//trace(action);
if (action == "Shift" && label == "Purchase Ammo" && callback != null) callback("Shift");
else if (callback != null) callback();
}
override public function update():void
{
super.update();
if (collidePoint(x, y, world.mouseX, world.mouseY))
{
if (Input.mousePressed && !Input.check(Key.SHIFT))
{
shiftClicked = false;
clicked = true;
}
if (Input.mousePressed && Input.check(Key.SHIFT))
{
//trace ("Shifty");
clicked = false;
shiftClicked = true;
}
if (Input.mouseReleased && clicked) click("");
if (Input.mouseReleased && shiftClicked) click("Shift");
hovered = true;
}
else hovered = false;
if (Input.mouseReleased) clicked = false;
if (hovered)
{
updateTooltip();
graphic = displayImage2;
}
else graphic = displayImage;
}
}
When I run it, it displays all but the last line of text (I guess I need a rep of 10 to post a screenshot). For example, the first button displays "Purchase" instead of "Purchase Ammo".
Has anyone ever run into this issue before, and if so how do you get around it?
I've ran into some problems with word wrap. It seems that for Text class the word wrap works correctly when you specify its width and height and then set the word wrap to true and important - resizable to false.
I was just having the exact same problem, try setting the height attribute, that solved for me.