2014-01-17 7 views
0

처음에는 볼 수 없도록 설정 한 4 개의 객관식 질문 (텍스트 필드가 포함 된 스프라이트)이 있습니다. 버튼을 클릭하면 표시되도록 설정 한 다음 올바른 대답 만 남긴 상태에서 알파 0으로 희미 해지기를 원합니다. 다음 코드는 이것을 수행하지만 addToStage 핸들러에서 initTweens()를 호출 할 때만 가능합니다. 버튼 클릭 이벤트 (playClickHandler)에서 호출하려고하면 알파 페이드가 발생하지 않습니다. 왜 누군가는 볼 수 있습니까?Tweens가 스테이지에 추가되었지만 버튼 클릭에 응답하지 않았습니다.

감사합니다.

package 
{ 
import com.greensock.TimelineLite; 
import com.greensock.TweenLite; 
import com.greensock.easing.*; 

import flash.display.Bitmap; 
import flash.display.GradientType; 
import flash.display.Graphics; 
import flash.display.Shape; 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.geom.Matrix; 
import flash.net.URLRequest; 
import flash.net.navigateToURL; 
import flash.text.TextField; 
import flash.text.TextFieldAutoSize; 
import flash.text.TextFieldType; 
import flash.text.TextFormat; 

import views.Icons; 

[SWF(width="400", height="350", backgroundColor="0xffffff")] 
public class game extends Sprite 
{ 
//sprites 
private var container:Sprite; 
private var question:Sprite = new Sprite(); 
private var answer1:Sprite = new Sprite(); 
private var answer2:Sprite = new Sprite(); 
private var answer3:Sprite = new Sprite(); 
private var answer4:Sprite = new Sprite(); 
private var explanation:Sprite = new Sprite(); 
private var playButton:Sprite; 

//text fields 
private var txtQuestion:TextField = new TextField(); 
private var txtAnswer1:TextField = new TextField(); 
private var txtAnswer2:TextField = new TextField(); 
private var txtAnswer3:TextField = new TextField(); 
private var txtAnswer4:TextField = new TextField(); 
private var txtExplanation:TextField = new TextField(); 
private var vBuffer:Number = 10; 

//strings for textfields 
private var currentQuestion:String; 
private var currentAnswer1:String; 
private var currentAnswer2:String; 
private var currentAnswer3:String; 
private var currentAnswer4:String; 
private var currentExplanation:String; 

private var questionSets:Array = []; 
private var timeline:TimelineLite = new TimelineLite(); 
private var fadeSpeed:Number = 3; 

private var bmpplayButton:Bitmap; 
private var centeredAnswerPosition:Number; 

//create a keyword which will trigger the presentation of a given questionSet 
private var keyWord:String; 

private var questionObj:Object; 

private var textWidth:Number = 400; 
private var textHeight:Number; 

public function game() 
{ 
this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler); 
} 

private function addedToStageHandler(e:Event):void 
{ 
bmpplayButton = new Icons.PlayButtonMedium(); 
loadData("amzn"); 
setUpQuestion(); 
//initTweens(); //this works 
} 

private function playClickHandler(e:MouseEvent):void 
{ 
makeVisible(); 
initTweens(); //code runs, but this doesn't work -- the alpha changes don't happen. 
} 


private function makeVisible():void 
{ 
answer1.visible = true; 
answer2.visible = true; 
answer3.visible = true; 
answer4.visible = true; 
explanation.visible = true; 
} 

private function initTweens():void 
{ 
timeline.insert(TweenLite.to(answer1,fadeSpeed, {autoAlpha:0, delay:4}),0); 
timeline.insert(TweenLite.to(answer3,fadeSpeed, {autoAlpha:0, delay:7}),0); 
timeline.insert(TweenLite.to(answer4,fadeSpeed, {autoAlpha:0, delay:10}),0); 
timeline.insert(TweenLite.to(answer2, 2, {x:100,scaleX:2, scaleY:2, delay: 12}),0); 
timeline.insert(TweenLite.to(explanation, fadeSpeed, {autoAlpha:1, delay:14}),0); 
timeline.append(TweenLite.delayedCall(3, clear)); 
} 



private function setUpQuestion():void 
{ 
container = new Sprite(); 
container.name = "container"; 
container.buttonMode = true; 
container.useHandCursor = true; 
addChild(container); 


txtQuestion.name = "txtQuestion"; 
txtQuestion.width = textWidth; 
txtQuestion.wordWrap = true; 
txtQuestion.multiline = true; 
txtQuestion.type = TextFieldType.DYNAMIC; 
txtQuestion.autoSize = TextFieldAutoSize.LEFT; 
question.addChild(txtQuestion); 

var textFormat:TextFormat = new TextFormat("Arial", 14, 0x000000, false, false, false, "", "", "left", 0, 0, 0, 0); 
txtQuestion.setTextFormat(textFormat); 
txtQuestion.defaultTextFormat = textFormat; 
txtQuestion.text = currentQuestion; 

answer1.y = question.y + question.height + vBuffer; 
txtAnswer1.width = textWidth; 
txtAnswer1.wordWrap = true; 
txtAnswer1.multiline = true; 
txtAnswer1.type = TextFieldType.DYNAMIC; 
txtAnswer1.autoSize = TextFieldAutoSize.LEFT; 
txtAnswer1.setTextFormat(textFormat); 
txtAnswer1.defaultTextFormat = textFormat; 
txtAnswer1.text = currentAnswer1; 
answer1.addChild(txtAnswer1); 
answer1.visible = false; 

answer2.y = answer1.y + answer1.height + vBuffer 
txtAnswer2.width = textWidth; 
txtAnswer2.wordWrap = true; 
txtAnswer2.multiline = true; 
txtAnswer2.type = TextFieldType.DYNAMIC; 
txtAnswer2.autoSize = TextFieldAutoSize.LEFT; 
txtAnswer2.setTextFormat(textFormat); 
txtAnswer2.defaultTextFormat = textFormat; 
txtAnswer2.text = currentAnswer2; 
answer2.addChild(txtAnswer2); 
centeredAnswerPosition = stage.stageWidth/2 - answer2.width/2; 
answer2.visible = false; 

answer3.y = answer2.y + answer2.height + vBuffer; 
txtAnswer3.width = textWidth; 
txtAnswer3.wordWrap = true; 
txtAnswer3.multiline = true; 
txtAnswer3.type = TextFieldType.DYNAMIC; 
txtAnswer3.autoSize = TextFieldAutoSize.LEFT; 
txtAnswer3.setTextFormat(textFormat); 
txtAnswer3.defaultTextFormat = textFormat; 
txtAnswer3.text = currentAnswer3; 
answer3.addChild(txtAnswer3); 
answer3.visible = false; 

answer4.y = answer3.y + answer3.height + vBuffer; 
txtAnswer4.width = textWidth; 
txtAnswer4.wordWrap = true; 
txtAnswer4.multiline = true; 
txtAnswer4.type = TextFieldType.DYNAMIC; 
txtAnswer4.autoSize = TextFieldAutoSize.LEFT; 
txtAnswer4.setTextFormat(textFormat); 
txtAnswer4.defaultTextFormat = textFormat; 
txtAnswer4.text = currentAnswer4; 
answer4.addChild(txtAnswer4); 
answer4.visible = false; 

explanation.y = answer4.y + answer4.height + vBuffer; 
explanation.alpha = 0; //hide it 
txtExplanation.width = textWidth; 
txtExplanation.wordWrap = true; 
txtExplanation.multiline = true; 
txtExplanation.type = TextFieldType.DYNAMIC; 
txtExplanation.autoSize = TextFieldAutoSize.LEFT; 
txtExplanation.y = txtAnswer4.y + txtAnswer1.height + vBuffer; 
txtExplanation.setTextFormat(textFormat); 
txtExplanation.defaultTextFormat = textFormat; 
txtExplanation.text = currentExplanation; 
explanation.addChild(txtExplanation); 
explanation.visible = false; 

playButton = new Sprite(); 
playButton.name = "play"; 
playButton.buttonMode = true; 
playButton.useHandCursor = true; 
playButton.addChild(bmpplayButton); 
playButton.x = stage.stageWidth/2 - playButton.width/2; 
playButton.y = explanation.y + explanation.height + 5*vBuffer; 
playButton.addEventListener(MouseEvent.CLICK, playClickHandler); 

container.addChild(question); 
container.addChild(answer1); 
container.addChild(answer2); 
container.addChild(answer3); 
container.addChild(answer4); 
container.addChild(explanation); 
container.addChild(playButton); 
} 


private function loadData(questionSet:String):void 
{ 
switch(questionSet) 
{ 
case "cap": 
currentQuestion = "What is the term for the number of a company's shares currently available for trading?"; 
currentAnswer1 = "The Cap" ; 
currentAnswer2 = "The Float"; 
currentAnswer3 = "The Book"; 
currentAnswer4 = "The Major Leagues"; 
currentExplanation = "If a large percentage of the float is 'short' then it can set up a short squeeze."; 
break; 
case "amzn": 
currentQuestion = "How much has Amazon gone up in the last 10 years?"; 
currentAnswer1 = "100%" ; 
currentAnswer2 = "10000%"; 
currentAnswer3 = "1000%"; 
currentAnswer4 = "400%"; 
currentExplanation = "Yes, it's gone up a hundredfold. Buy and hold!"; 
break; 
} 

} 

private function clear():void 
{ 
question.visible = false; 
answer1.visible = false; 
answer2.visible = false; 
answer3.visible = false; 
answer4.visible = false; 
explanation.visible = false; 
} 
} 
} 

답변

-1

. 대신 선언시 인스턴스의

:

private var timeline:TimelineLite = new TimelineLite(); 

난 그냥 내가 다음() 함수 initTweens에서 인스턴스화

private var timeline:TimelineLite; 

했다. 그것은 트릭을했다. 어떤 이유로 타임 라인은 호출 될 때마다 선언 될 때 인스턴스화 된 덕분에 자동으로 실행됩니다.

+0

이것은 이해가되지 않습니다. 대답에서 말했듯이 이것은 올바른 해결책이 아닙니다. 이제 autoAlpha를 사용하고 있었지만 플러그인을 가져 오지 않았기 때문에 어쨌든 오류가 발생했습니다 :'import com.greensock.plugins.AutoAlphaPlugin;' 불행히도이 표시는 정확하며 문제의 진정한 대답은 아닙니다 autoAlpha 플러그인으로 처리되는 가시성을 제어 할 수 있습니다. –

0

문제는 playClickHandler(e:MouseEvent)에서라는 makeVisible() 함께. 댓글을 달거나 제거 할 경우 ADDED_TO_STAGE 이벤트와 동일한 방식으로 작동합니다.

이유는 AutoAlpha 플러그인이 사용자의 시야를 제어하기 때문에 makeVisible()을 호출 할 필요가 없기 때문입니다.

자료 : I 해결책을 알아 냈 http://www.greensock.com/as/docs/tween/com/greensock/plugins/AutoAlphaPlugin.html

+0

안녕하세요. 의견을 보내 주셔서 감사합니다. 나는 당신이 그것을 테스트했는지 나는 모른다. 나는 아직 그렇지 않다. 그러나 나는 대답으로 게시하고있는 해결책을 찾았습니다. – David

+0

나는 그걸 시험해 봤는데 그게 수정본 이었어 –

+0

내가 가서 그걸 시험해 봤는데 내가 그 변화를 만들면 flash.display.Sprite에 autoAlpha 속성이없고 기본값이 없다는 오류가 생겼다. – David

관련 문제