Depth or dynamic text issue?
Copy link to clipboard
Copied
I have a fla(flash CC 13.1) with several layers if I add a keyframe and swap movie clip it will cause an anomaly were the if a popup box is open, the dynamic text box text will keep old text with new text on top (titles). We used an array to populate the text, and some of the other features are using addChild.
Lesson AS file there
package Template {
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.SimpleButton;
import flash.text.TextField;
import Template.Tools
import flash.sampler.StackFrame;
import Template.Classification;
public class Lesson extends MovieClip {
public var AssetsMenu:PopupWindow = new PopupWindow();
public var IndexMenu:indexMenu_mc = new indexMenu_mc();
public var LessonInfoPopup:info_mc = new info_mc();
public var LCTextPopup:lcText_mc = new lcText_mc();
public var LessonVideoSingle:vidSinglePop_mc = new vidSinglePop_mc();
public var SlideTitles:Array = new Array(totalFrames); // An array that will hold the slide titles
// Various information read from the SCORM manifest files.
public var LessonTitle:String = "";
public var SCOTitle:String = "";
var menuLinks:XMLList; // MenuLinks section of the Site Settings XML file.
var lastFrameVisited:int = 0;
public function Lesson() {
initializePopupWindows();
initializeLessonInfo();
initializeSCOInfo();
initializeSiteSettings();
// Set the slide total number of slides for the slide location display.
nav_mc.slideTotal.text = totalFrames;
this.addEventListener(Event.ENTER_FRAME, initializeSlide);
}
function initializePopupWindows()
{
// Initilize the Assets window.
addChild(AssetsMenu);
// Initialize the Index window.
IndexMenu.txtIndexList.text = "";
addChild(IndexMenu);
IndexMenu.x = 160;
IndexMenu.y = 46;
// Initialize the Lesson info window.
addChild(LessonInfoPopup);
LessonInfoPopup.Center();
addChild(LessonVideoSingle);
LessonVideoSingle.CenterX();
LessonVideoSingle.y = 50;
// Initialize the LCText window.
addChild(LCTextPopup);
// CenterX should work, but for some reason the LCTextPopup has an incorrect width at this point.
// For now we'll hard-code the width to 910.
//LCTextPopup.CenterX();
LCTextPopup.x = (this.width - 910) / 2;
LCTextPopup.y = nav_mc.y - LCTextPopup.height - 10;
}
function initializeLessonInfo()
{
// Load the imsmanifest file.
var urlRequest:URLRequest = new URLRequest("../imsmanifest.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, lessonInfoComplete);
urlLoader.load(urlRequest);
}
function lessonInfoComplete(e:Event)
{
// The imsmanifest file has completed loading.
// Get the manifest XML.
var xmlManifest:XML = new XML(e.currentTarget.data);
xmlManifest.ignoreWhite = true;
xmlManifest.ignoreComments = true;
var scorm:Namespace = xmlManifest.namespace();
// Get the lesson title from the XML.
LessonTitle = xmlManifest.scorm::organizations.scorm::organization.scorm::title;
// Set the title on the Lesson Info window.
setText(LessonInfoPopup.txtTitle, LessonTitle);
}
function initializeSCOInfo()
{
// Load the LOMInfo file.
var urlRequest:URLRequest = new URLRequest("LOMinfo.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, scoInfoComplete);
urlLoader.load(urlRequest);
}
function scoInfoComplete(e:Event)
{
// The LOMInfo file has completed loading.
// Get the LOMInfo XML.
var xmlLOMInfo:XML = new XML(e.currentTarget.data);
xmlLOMInfo.ignoreWhite = true;
xmlLOMInfo.ignoreComments = true;
var sco:Namespace = xmlLOMInfo.namespace();
// Get the SCO information from the XML.
SCOTitle = xmlLOMInfo.sco::general.sco::title.sco::langstring;
}
function initializeSiteSettings()
{
// Load the SiteSettings file.
var urlRequest:URLRequest = new URLRequest("../SiteSettings/SiteSettings.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, siteSettingsComplete);
urlLoader.load(urlRequest);
}
function siteSettingsComplete(e:Event)
{
// The SiteSettings file has completed loading.
// Get the SiteSettings XML.
var xmlSettings:XML = new XML(e.currentTarget.data);
xmlSettings.ignoreWhite = true;
xmlSettings.ignoreComments = true;
// Get the menuLinks from the SiteSettings XML.
menuLinks = xmlSettings.menuLinks;
createAssetsMenu();
}
function createAssetsMenu()
{
var menuButtons:Array = new Array();
var largestWidth:Number = 0; // This will be used to resize the buttons so that all the text fits and all the sizes match.
var centerOfAssetsButton:Number = (nav_mc.assets_btn.x + (nav_mc.assets_btn.width) / 2);
// Add Section Info button
var info:tab_mc = new tab_mc;
info.tabText.autoSize = "left";
info.tabText.text = "Revision Info"; // This is the text that will be dsiplayed on the button.
info.actionToTake = ShowLessonInfo; // This button will call the "ShowLessonInfo" function when clicked.
largestWidth += info.tabText.textWidth;
menuButtons.push(info);
// Loop throug each of the items in the menuLinks that have "inLecture" set to "true".
// Create a button for each menu link and save it in an array.
// After all of the buttons are created, we'll loop through the button array to resize and position each one.
for each (var linkItem:XML in menuLinks.linkItem.(@inLecture == true))
{
var item:tab_mc = new tab_mc();
item.tabText.autoSize = "left";
item.tabText.text = linkItem.@item; // This is the text that will be displayed on the button.
item.fileToOpen = linkItem.@path; // This is the file that will be opened when the button is clicked.
// Check the text width and reset largestWidth if needded.
if (item.tabText.textWidth > largestWidth)
largestWidth = item.tabText.textWidth;
// Add the button to the array.
menuButtons.push(item);
}
// Loop through the array of buttons to resize and position them and then add them to the Assets menu.
for (var i:int = 0; i < menuButtons.length; i++)
{
// Resize the button background to the size of the longest text in the group plus some padding.
menuButtons.tabBg.width = largestWidth + 40;
// Position the button.
menuButtons.x = 0;
menuButtons.y = menuButtons.height * i;
// Center the text within the button.
menuButtons.tabText.x = (menuButtons.width - menuButtons.tabText.width) / 2;
// Add the button to the Assets menu.
AssetsMenu.addChild(menuButtons);
}
// Position the Assets menu over the Assets button
AssetsMenu.x = centerOfAssetsButton - (AssetsMenu.width / 2);
AssetsMenu.y = nav_mc.y - AssetsMenu.height;
}
public function ShowLessonInfo()
{
LessonInfoPopup.ToggleOnOff();
}
public function ShowSingleVideo(sourceFile:String, classification:Classification)
{
LessonVideoSingle.vidPlayer.source = sourceFile;
LessonVideoSingle.vidPlayer.stop();
LessonVideoSingle.mcClassification.visible = (classification != Classification.NONE);
LessonVideoSingle.mcClassification.txtTop.text = classification.Text;
LessonVideoSingle.mcClassification.txtBottom.text = classification.Text;
LessonVideoSingle.mcClassification.txtTop.textColor = classification.Color;
LessonVideoSingle.mcClassification.txtBottom.textColor = classification.Color;
if(!LessonVideoSingle.visible)
LessonVideoSingle.ToggleOnOff();
}
public function InitializeSlideTitles()
{
if(IndexMenu.txtIndexList.text == "")
{
// Initialize the text that will be displayed in the index.
for (var i:int = 1; i <= this.totalFrames; i++)
{
IndexMenu.txtIndexList.appendText(i + " - " + SlideTitles + "\n");
}
IndexMenu.scrollBar.update();
}
}
function initializeSlide(e:Event)
{
// Check if currentFrame different than the last frame visited. This just ensures that this code only runs once
// because the ENTER_FRAME event occurs continually.
if(currentFrame != lastFrameVisited)
{
if (currentFrame > 1)
{
// Enable the Back and Text buttons for frames other than frame 1.
Tools.enableButton(nav_mc.back_btn);
Tools.enableButton(nav_mc.text_btn);
}
else
{
// For frame 1, disable the Back and Text buttons.
Tools.disableButton(nav_mc.back_btn);
Tools.disableButton(nav_mc.text_btn);
// Set the lesson title and SCO title on the first slide.
setText(lessonName_txt, LessonTitle);
setText(txtTextSCOTitle, SCOTitle);
}
if (currentFrame == totalFrames)
{
// Disable the Next button on the last frame.
Tools.disableButton(nav_mc.next_btn);
}
else
{
// Enable the Next button on frames other than the last frame.
Tools.enableButton(nav_mc.next_btn);
}
// Hide any popup windows that are showing.
for (var i:int = 0; i < this.numChildren; i++)
{
var child = this.getChildAt(i);
if (child is PopupWindow)
{
if(child.visible) child.ToggleOnOff();
}
}
// For all frames, set the slide title, slide location, and update the lecture text.
txtSlideTitle.text = SlideTitles[currentFrame];
nav_mc.slideLocation.text = this.currentFrame;
LCTextPopup.updateDisplay(currentFrame);
// Reset the last frame visited.
lastFrameVisited = currentFrame;
}
}
function setText(textFieldObj:TextField, textString:String)
{
// Check for the existence of each text box first. This ensures that the
// objects in the lesson can be edited/removed without causing an error.
if(textFieldObj)
{
textFieldObj.text = textString;
}
}
}
}
Popup AS file
Package Template {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.SoundMixer;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import fl.video.FLVPlayback;
public class PopupWindow extends MovieClip {
public var RemoveOnClose:Boolean = false;
public function PopupWindow() {
this.visible = false; // The window is hidden by default
// If a button called "close_btn" exists, add an event listener that will hide the window.
if(close_btn)
{
close_btn.addEventListener(MouseEvent.CLICK, closePopup);
}
// if a button called "drag_btn" exists, add event listeners that will allow dragging of the window.
if(drag_btn)
{
drag_btn.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
drag_btn.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}
}
function closePopup(e:MouseEvent):void
{
// Hide the popup window.
this.ToggleOnOff();
}
function beginDrag(e:MouseEvent)
{
this.startDrag();
}
function endDrag(e:MouseEvent)
{
this.stopDrag();
}
public function ToggleOnOff()
{
this.visible = !this.visible;
if(this.visible)
{
parent.swapChildren(this, parent.getChildAt(parent.numChildren - 1));
}
else
{
if(RemoveOnClose)
{
this.parent.removeChild(this);
}
else
{
stopAllPlayback(this);
SoundMixer.stopAll();
}
}
}
public function CenterX()
{
// Center the window horizontally within the parent.
if(this.parent != null)
{
this.x = (this.parent.width - this.width) / 2;
}
}
public function CenterY()
{
// Center the window vertically within the parent.
if(this.parent != null)
{
this.y = (this.parent.height - this.height) / 2;
}
}
public function Center()
{
// Center the window both horizontall and vertically within the parent.
CenterX();
CenterY();
}
private function stopAllPlayback(container:MovieClip)
{
// Loop through all the children looking for FLVPlayback objects.
// If one is found, stop it.
for (var i:int = 0; i < container.numChildren; i++)
{
var child:DisplayObject = container.getChildAt(i);
if (child is FLVPlayback)
{
var flvp:FLVPlayback = child as FLVPlayback;
flvp.playheadTime = 0;
flvp.stop();
}
else
{
if(child is MovieClip)
{
var mc:MovieClip = child as MovieClip;
if (mc.numChildren > 0)
stopAllPlayback(mc);
}
}
}
}
}
}
Timeline code
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.media.SoundMixer;
import flash.events.Event;
// NOTE: The class for this document is Lackland.Lesson.
// Additional code can be found in ..\scripts\Lackland\Lesson.as.
// No visible slide title on the first frame.
txtSlideTitle.visible = false;
stop();
//Mouse navigation;
nav_mc.back_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent)
{
prevFrame();
SoundMixer.stopAll();
}
nav_mc.next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:MouseEvent):void
{
nextFrame();
SoundMixer.stopAll();
}
nav_mc.exit_btn.addEventListener(MouseEvent.CLICK, closeBrowser);
function closeBrowser(e:MouseEvent):void
{
ExternalInterface.call("window.open","","_self");
ExternalInterface.call("window.close");
}
nav_mc.index_btn.addEventListener(MouseEvent.CLICK, showIndex);
function showIndex(e:MouseEvent):void
{
InitializeSlideTitles();
IndexMenu.ToggleOnOff();
}
nav_mc.assets_btn.addEventListener(MouseEvent.CLICK, showAssetsMenu);
function showAssetsMenu(e:MouseEvent)
{
AssetsMenu.ToggleOnOff();
}
nav_mc.text_btn.addEventListener(MouseEvent.CLICK, showLectureText);
function showLectureText(e:MouseEvent):void
{
LCTextPopup.ToggleOnOff();
}
//Keyboard navigation;
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown, false);
function myKeyDown(e:KeyboardEvent):void
{
//stage.focus = stage;
switch (e.keyCode)
{
case Keyboard.LEFT :
prevFrame();
SoundMixer.stopAll();
break;
case Keyboard.RIGHT :
nextFrame();
SoundMixer.stopAll();
break;
case Keyboard.HOME :
this.gotoAndStop(1);
SoundMixer.stopAll();
break;
case Keyboard.END :
this.gotoAndStop(totalFrames);
SoundMixer.stopAll();
break;
}
}
//Keeps focus on Stage so keyboard commands will work on Video Library frames
this.addEventListener(Event.ENTER_FRAME,stageFocus, false,0 , true);
function stageFocus(e:Event):void
{
stage.focus = stage;
}
Copy link to clipboard
Copied
that looks like there are two textfields overlapping. to confirm, assign a background to the topmost.
Copy link to clipboard
Copied
We confirmed that there is only one text box. When we where in CS5 this never happened, but it only happens in CC and if we add a keyframe to swap classfication banners (movieClip). It has me scratching my head.
Copy link to clipboard
Copied
how'd you confirm there was only one textfield?
Copy link to clipboard
Copied
I turned on outline and moved the text box to see if one was behind it. Also if only one keyframe on the class banner layer this does not happen. titles are dynamic text with the instance name txtSlideTitle and if there where two on the same frame it would give me an error.
Copy link to clipboard
Copied
that's not sufficient.
when you use code to add textfields (or other objects), checking the timeline/layers/frames isn't enough.
Copy link to clipboard
Copied
I get that, but none of the code is adding a text box/title. it is just populating the text box on the stage with the instance name via the array. We also noticed the if we click on the assets or index button the same thing happens. I know that these items added by the addChild method. I wonder when we add a keyframe and swap the symbol if it may be re-initializing the script or messing up the layering/depth.
Copy link to clipboard
Copied
it's hard to determine without inspecting your fla.
Copy link to clipboard
Copied
I love to post the file, but I do not see any where to do that in this forum.
Copy link to clipboard
Copied
you would have to upload to a file server (eg, dropbox).
but i don't download and correct files unless i'm hired.
Copy link to clipboard
Copied
Does not matter I have no authority to hire.

