2012-05-08 5 views
0

저는 as3을 처음 사용하지만 아직 배우지 않았습니다. 사용자가 텍스트 필드 입력과 함께 나타나는 컨테이너를 만들어서 사용자가 '게시물'을 만들 수 있습니다. 애니메이션이 완료되면 자동으로 스테이지에서 애니메이션을 제거하면 트리거됩니다.AS3 개체가 1.5 - 2 분 후에 불가피하게 사라집니다.

그러나 약 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); 
    } 
} 
+1

이 기능을 사용하여 동시에 여러 게시물을 만드시겠습니까? 가비지 컬렉션에 대한 귀하의 요지를 참조하십시오,하지만 그것은 무대 요소를 제거해서는 안되므로 변수를 선언하면 쓰레기로부터 보호해야합니다. – Sidrich2009

답변

0

에게, 감사 알파의 증가 기 아무 반올림 문제가 없는지 당신은 사실을 알고 계십니까? 나는 알파의 정수 값을 검사 할 것이고 실제 부동 소수점 값은 검사하지 않을 것이다. 또는 일부 작은 값의 FUZZ에 대해서는 fuzz 비교 (alpha> = 1-FUZZ & & alpha < = 1 + FUZZ)를 수행하십시오.

+0

알파가 증가하고 있으므로 문제가되지 않아야합니다. 조건이 트리거되지 않습니다. 어쨌든 이것은 일반적으로 명심해야 할 좋은 것입니다. –

관련 문제