Solved

Flash CS4 - AS3 Questoin about Scenes

Posted on 2010-11-14
2
625 Views
Last Modified: 2013-11-11
Greetings, all!

I have quite a bit of background in programming, but am very new to Flash.  I've been taking a flash course for about two months now, and we just started on AS3.  So for my latest project, I wanted to incorporate some AS3 into my Flash movie, but I think that I'm still not understanding exactly how it works, so if someone can explain what I'm doing wrong, I would appreciate it greatly.

Basically, what I have is a movie clip that contains two layers - one is a colored circle, the other is a rectangular image of mars.  The colored circle layer is above the layer containing the image of mars, and the colored circle layer is set as a mask layer.  I have it rotating over a specific number of frames, so when I drag this onto my stage in Scene 1 and play it, I get the illusion of Mars spinning.  Pretty nifty.

At any rate, I found and modified some AS3 on the internet to mimic "typewriter text" (where it types one letter at a time on the screen, rather than the entire contents of a textbox).  This effect is EXACTLY what I want....

But when I create a new scene, it get an error that states: "Cannot access a property or method of a null object reference."  So I'm very curious if I need to somehow revamp the AS3 to specify which scene it works in?

I've attached the ActionScript into a code snippet.

Also, I am attaching my .fla file as well, in case anyone feels the need to take a look at it.  It is not large at all.

My primary point that I'm trying to achieve, is to play Scene 1, which has Mars spinning in space with some green typewriter text, and after that is done I want to transition to Scene 2, which will be an animation of an astronaut inside of a space shuttle (still working on the art in photoshop for that one...).

However, as soon as I add a second scene to the project, that error shows up!  

Please help?


var str1:String = 'In the year 2009, the Mars Rover Discovered something that shattered humanity\'s view on their place in the cosmos forever...';

var i:uint = 0;

var timer:Timer = new Timer(100);

timer.start();

timer.addEventListener(TimerEvent.TIMER,gotime);

function gotime(e:TimerEvent) {
	
	textbox_txt.appendText(str1.charAt(i));
	i++;
	
	if(i>=str1.length) {
		timer.stop();
	}
}

Open in new window

Introduction.fla
0
Comment
Question by:ThatSharepointGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
scooby_56 earned 250 total points
ID: 34130643
Just add

stop()

At the top of your code in scene1 - this will prevent if jumping between scene1 and scene2 continuously.

In your code, to go to the next scene (add a click event or something) use something like;

gotoAndStop (1, "Scene 2" );
0
 
LVL 30

Assisted Solution

by:Britt Thompson
Britt Thompson earned 250 total points
ID: 34130656
The timer isn't stopping before it moves to the next scene. So, to make sure it stops add a "stop();" to the 1st keyframe in the main scene and add a "gotoAndPlay(1, "Scene 2"); to the code to make sure the timer is stopped before moving.

      if(i>=str1.length) {
            timer.stop();
            gotoAndPlay(1,"Scene 2");
      }
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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