Solved

as3 movieclip disappears

Posted on 2009-05-19
6
723 Views
Last Modified: 2013-11-11
Hi There Experts,

I'm trying to do something which I thought would be relatively easy but isn't working. In the timer event of my class linked to the fla i'm working on, in my ontick timer event (which is working for other things) I'm trying to update a MovieClip called score which has a TextBox in it (called scoreText) by .05 every "tick". I'm not getting any erros with the below code but the text is flashing up for a millisecond and then disappearing. Any ideas why?

cheers,
~ Jazz
//the movieclip declaration

public var score:Score;

//the currentScore, used to keep track of the score, declaration

public var currentScore;
 

//the timer event in the same class as the above declarations

public function onTick(event:TimerEvent):void

		{

			currentScore = currentScore + 1;

			score.scoreText.text = String(currentScore);

			//other unrelated code

		}
 

//the Score class.

package 

{

	import flash.display.MovieClip;

	import flash.text.TextField;

	

	public class Score extends MovieClip 

	{

		public function Score()

		{

			

		}

	}

}
 

//the linked Score MovieClip in my library has a dynamic text field in it wth the instance name

//scoreText

Open in new window

0
Comment
Question by:Jazzua
  • 3
  • 3
6 Comments
 

Author Comment

by:Jazzua
ID: 24429184
oh, and i've also attached the score movieclip to the stage with the following code:
score = new Score()

score.x = 350;

score.y = 50;

addChild(score);

Open in new window

0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24434157

if you see if flash on the screen and then go away, normally this happens to me when I have the movieclip being set to visible false or alpha 0 in the code, cause there is some latency in the code.

other things to check are whether or not another movieclip is on top of it, and could be alpha = 0.

the last thing that normally makes a textfield go blank is not having the font embedded, or the font is actually set to white an accident in the code.


try commenting out this line....   score.scoreText.text = String(currentScore);

if it was something to do with your data, and you comment it out, then the text would not flash, but instead stay there...


try to trace out String( currentScore ); and also just plain currentScore...  it could be that Flash doesn't like converting something to a string...


hope I got you started in the right direction...


rp / ZA

 
0
 

Author Comment

by:Jazzua
ID: 24439147
thanks for your help rascalpants,
i tried your suggestion and commented out: "score.scoreText.text = String(currentScore);".
when I did this I could see the default text I had entered in the TextField in my "score" MovieClip at design time ("00").
I then tried just changing the textfield text assignment to:  "score.scoreText = "Test";" and embdded the correct characters. The text didn't show up. So i traced: "trace(score.scoreText)" and got "Test" returned in the output window. So it appears the text property is being changed correctly!
So currently the text will show if not changed in the code, but any attempt to programmatically change the text makes the text dissapear.
???????????????????????????????
this has me completely stumped. Any other ideas?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
rascalpants earned 500 total points
ID: 24442054
well first of all, you have to set the text by using the "text" property...

try this...

score.scoreText.text = "Test";

other than that... make sure all of your instance names are correct... you might be missing one.
can you trace out score.scoreText   ie  trace(score.scoreText);  and see if it have been assigned an instance name?


rp / ZA
0
 

Author Comment

by:Jazzua
ID: 24450964
It turned out I had been using ScoreText rather than scoreText, though it wasn't being picked up by the compiler because I had a ScoreText class from earlier development that I had forgotten about. I feel like an idiot, but its working now, and your advice helped me track down the problem. Cheers :)
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24451085
LOL...  sorry, that happens to the best of us...

BUT... I would start naming your movieclips with an underscore and extention... like   scoreText_mc...  that way you never have a Class or a textbox that is named the same...


rp / ZA
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Accessing Live Dynamic Stream 6 190
Embedded Webpage Videos don't auto play on Windows 7 1 103
Adobe Presenter not Publishing Slide Theme 17 120
Open Source MP4 Flash Player 2 169
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now