Class A loads images on the stage while class B loads text. On clicking on class A, I would like class B to load the corresponding text. I traced the text that needs to be loaded and it is correctly loaded. The text is however not updated.
onClick function in Class A:
private function onClick(event : MouseEvent) : void
{
// Always display product clicked on as center image
cover = event.target as DisplayObject;
coverIndex = covers.indexOf(cover);
show(coverIndex); // Show the index number of the current displayed object
selectedCoverIndex = getCoverIndex();
trace("Index of Selected Cover : " + selectedCoverIndex);
// Ensures the text of class B is updated by reloading the class:
if(pl)
{
removeChild(pl); // apparently not working since pl is not appearing
}
pl = new ProductSummaryLabel(); // ProductSummaryLabel is the name of class B
addChild(pl);
}
Here is class B:
(...)
public function drawProductSummaryLabel() : void
{
// Create a holder that will contain the footer label.
var productInfoHolder : Sprite = new Sprite();
// Add the holder to the stage.
addChild(productInfoHolder);
//Create font for the label
var format1 : TextFormat = new TextFormat();
format1.font = "DejaVu Sans";
format1.color = 0x000000;
format1.size = 12;
format1.bold = true;
format1.align = "left"; // or center?
productSummaryLabel.defaultTextFormat = format1;
productSummaryLabel.wordWrap = true;
productSummaryLabel.selectable = true;
productSummaryLabel.alwaysShowSelection = true;
productSummaryLabel.width = 846;
productSummaryLabel.height = 80;
productSummaryLabel.text = "loading text"; // Initial text before its replaced
productSummaryLabel.visible = false; // Or shall I make it true so you see loadin text?
addChild(productSummaryLabel);
// Create the button
var button : Sprite = new Sprite();
// Disable the mouse events of all the objects within the button.
button.mouseChildren = false;
// Make the sprite behave as a button.
button.buttonMode = true;
// Create an original state for the button.
var originalState : Sprite = new Sprite();
originalState.graphics.beginFill(0xFFFFFF);
// Follows format of: x, y, width, height
originalState.graphics.drawRect(0, 0, 846, 80); // Apparently roundRect is possible!!!
originalState.alpha = 0.5;
originalState.name = "original";
// Create a hovering state for the button.
var hover : Sprite = new Sprite();
hover.graphics.beginFill(0xCCCCCC);
hover.graphics.drawRect(0, 0, 846, 80);
hover.name = "hover";
// Add the states to the button as well as the label.
button.addChild(originalState);
button.addChild(hover);
button.addChild(productSummaryLabel);
// Position the text to the center of the box
productSummaryLabel.x = (button.height/2) - (productSummaryLabel.height/2); // footerLabel.x = button.x for left align.
productSummaryLabel.y = (button.height/2) - (productSummaryLabel.height/2); // Center align looks better than left align!
// Add mouse events to the button.
button.addEventListener(MouseEvent.MOUSE_OVER, displayMouseOverState);
button.addEventListener(MouseEvent.MOUSE_OUT, displayMouseOutState);
button.addEventListener(MouseEvent.CLICK, displayMessage);
// Add the button to the holder.
productInfoHolder.addChild(button);
// Postion The Menu.
productInfoHolder.x = 80;
productInfoHolder.y = 275;
// Hide the over state of the button.
hover.alpha = 0;
trace("Step 9: Product Summary Label is drawn now.");
}
public function setLabel() : void
{
// Summary text depends on coverIndex, i.e. which image is currently in the center
coverIndex = CoverFlow.selectedCoverIndex; // creates a new copy of this value everytime
trace("Cover Index (Product Summary Label class setLabel()): " + coverIndex);
var desiredSummaryString : String = uebersicht[coverIndex];
trace("Product summary text: " + desiredSummaryString);
productSummaryLabel.text = desiredSummaryString;
productSummaryLabel.visible = true;
}