0

我是 as3 的新手,但我一直在学习。我正在创建一个带有文本字段输入的容器,以便用户可以创建一个“帖子”。当动画从舞台中移除时会触发此事件,它在完成后会自动执行。

然而,大约 1.5-2 分钟后,容器莫名其妙地消失了。这是一个问题,因为用户很可能希望花费 2 分钟以上的时间来发帖。我一生都无法弄清楚为什么会发生这种情况,这可能是垃圾收集问题吗?

非常感谢您的任何帮助,谢谢,

var titleText:Title = new Title();
var titleInput:TextField = new TextField();

var categoryText:Category = new Category();
var categoryInput:TextField = new TextField();

var postText:Text = new Text();
var postInput:TextField = new TextField();

//setup text formats to be used
var postCreationTextFormat:TextFormat = new TextFormat();

postCreationTextFormat.font = "arial";
postCreationTextFormat.size = 20;
postCreationTextFormat.align = "left";
postCreationTextFormat.leftMargin = 2;


//Fade In Post Creation Box after Seed to Bud Animation.
seedToBud.addEventListener(Event.REMOVED_FROM_STAGE, createPostInput);

//Some variables to declare for the createPostInput function.
var postCreationContainer:PostCreationContainer = new PostCreationContainer;
var contentWindow:ContentWindow = new ContentWindow;
var postCreationInputBoxes:PostCreationInputBoxes = new PostCreationInputBoxes;
var thumb:Thumb = new Thumb;
var track:Track = new Track;
var scrollDownArrow:ScrollDownArrow = new ScrollDownArrow;
var scrollUpArrow:ScrollUpArrow = new ScrollUpArrow;

function createPostInput(event:Event)
{
    addChild(postCreationContainer);    
    postCreationContainer.x = 230;
    postCreationContainer.y = 400;

    postCreationContainer.addChild(track);
    track.x = 428;
    track.y = 25;

    postCreationContainer.addChild(thumb);
    thumb.x = 418;
    thumb.y = 25;

    postCreationContainer.addChild(scrollDownArrow);
    scrollDownArrow.x = 418;
    scrollDownArrow.y = 269;

    postCreationContainer.addChild(scrollUpArrow);
    scrollUpArrow.x = 418;
    scrollUpArrow.y = 6;

    postCreationContainer.addChild(contentWindow);
    contentWindow.x = 6;
    contentWindow.y = 6;

    postCreationContainer.addChild(postCreationInputBoxes);
    postCreationInputBoxes.x = 6;
    postCreationInputBoxes.y = 6;

    postCreationContainer.alpha = 0;
    postCreationContainer.addEventListener(Event.ENTER_FRAME, fadeInCreatePostInput);

    postCreationInputBoxes.addChild(titleText);
    titleText.x = 0;
    titleText.y = 0;

    postCreationInputBoxes.addChild(titleInput);

    postCreationInputBoxes.addChild(categoryText);
    categoryText.x = 0;
    categoryText.y = 60;

    postCreationInputBoxes.addChild(categoryInput);

    postCreationInputBoxes.addChild(postText);
    postText.x = 0;
    postText.y = 124;

    postCreationInputBoxes.addChild(postInput); 

    titleInput.defaultTextFormat = postCreationTextFormat;
    titleInput.type = "input";
    titleInput.multiline = false;
    titleInput.wordWrap = false;
    titleInput.maxChars = 150;
    titleInput.border = true;
    titleInput.width = 403;
    titleInput.height = 30;
    titleInput.x = 0;
    titleInput.y = 32;
    titleInput.background = true;
    titleInput.backgroundColor = 0xFFFFFF;

    categoryInput.defaultTextFormat = postCreationTextFormat;
    categoryInput.type = "input";
    categoryInput.multiline = false;
    categoryInput.wordWrap = false;
    categoryInput.maxChars = 150;
    categoryInput.border = true;
    categoryInput.width = 403;
    categoryInput.height = 30;
    categoryInput.x = 0;
    categoryInput.y = 96;
    categoryInput.background = true;
    categoryInput.backgroundColor = 0xFFFFFF;

    postInput.defaultTextFormat = postCreationTextFormat;
    postInput.type = "input";
    postInput.multiline = true;
    postInput.wordWrap = true;
    postInput.maxChars = 500;
    postInput.border = true;
    postInput.width = 403;
    postInput.height = 361.5;
    postInput.x = 0;
    postInput.y = 156;
    postInput.background = true;
    postInput.backgroundColor = 0xFFFFFF;

    stage.focus = titleInput;
    seedToBud.removeEventListener(Event.REMOVED_FROM_STAGE, createPostInput);
}

function fadeInCreatePostInput(event:Event):void
{
    postCreationContainer.alpha += 0.05;
    if (postCreationContainer.alpha == 1)
    {
        postCreationContainer.removeEventListener(Event.ENTER_FRAME, fadeInCreatePostInput);
    }
}
4

1 回答 1

0

您是否知道您的 alpha 增量器没有舍入问题?我会检查 alpha 的整数值,而不是真正的浮点值。或者,对一些小的 FUZZ 值进行模糊比较(alpha >= 1-FUZZ && alpha <= 1+FUZZ)。

于 2012-05-08T18:59:22.787 回答