5 Replies - 11877 Views - Last Post: 26 April 2009 - 01:12 PM

#1 Leon575  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 09

MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 12 March 2009 - 04:33 PM

Hi.
I'm making a survey with questions and Radiobuttons. I'm testing with 2 questions so far. And I was thinking about putting each question on seperate frames, and use navigation buttons like "gotoAndStop(2)" etc.
I don't know if this is the best way to structure a survey, though.

So far, I have MovieClip1 (question 1) on Frame 1 and MovieClip2 (question 2) on Frame 2. And a MovieClip-button "Next" on Frame 1 and a MovieClip-button "Check result" on Frame 2.

I'm using a Document Class for the actionscript code (Main.as).

In the constructor, I have added eventlisteners for the next-button and result-button, like this:

next.addEventListener(MouseEvent.CLICK, nextClick);
result.addEventListener(MouseEvent.CLICK, resultClick);


And the functions for the click events look like this for now:
function nextClick(e:MouseEvent):void
{
	  gotoAndStop(2);
}

function resultClick(e:MouseEvent):void
{
		
}

But obviously I get an error because the result-button is placed on Frame 2, and the constructor can't find it(?).

I get this error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main$iinit()


Is there a way to specify that the "result"-instance is at Frame 2 or something?
Feel free to come up with suggestions for how to better structure a survey.

Is This A Good Question/Topic? 0
  • +

Replies To: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

#2 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 12 March 2009 - 11:04 PM

this may be a dirty little hack. i don't think i would do this again. but then again, i don't use timelines anymore.

back when i did. i would put all the instances(movieclips) that are referenced in your document class on the stage on frame 1. then where you need it placed (frame 2) make it a keyframe.
on frame 1 (or all frames before you want it to appear) turn it's visibility off, alpha set to 0 and/or move it waaay off stage.
then on frame 2, make it visible and positioned where you want it.

this way, you don't see the movieclip on frame 1, but you can still reference it in the external as script, add listeners, etc.

does this make sense?
Was This Post Helpful? 1

#3 Leon575  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 09

Re: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 13 March 2009 - 09:40 AM

Thank you for your quick reply.
Yeah, this makes perfectly good sense. I'm definitely gonna use either alpha0/1 or position outside the stage.
I guess the most comon thing when using actionscript in a Document Class is to avoid the main timeline and just use frame 1. Timeline animations can be done inside MovieClips.
Was This Post Helpful? 0
  • +
  • -

#4 Leon575  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 09

Re: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 23 March 2009 - 04:14 PM

View PosttheRemix, on 12 Mar, 2009 - 10:04 PM, said:

back when i did. i would put all the instances(movieclips) that are referenced in your document class on the stage on frame 1. then where you need it placed (frame 2) make it a keyframe.


What do you mean with "make it a keyframe"?

Now I'm struggling with how to structure the navigation a decent way for 15 questions.
When the "Check result" button is clicked, some code is checking which radiobuttons is chosen and then add values to certain variables. All the questions have to be at frame 1 for it to work, because the code is in the Document Class.

The way I'm doing it now, I'll have to use alot of next-buttons and previous-buttons... which is pretty time consuming. Wish I could do this with one next-button and one previous-button.
Was This Post Helpful? 0
  • +
  • -

#5 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 25 April 2009 - 04:10 PM

View PostLeon575, on 23 Mar, 2009 - 03:14 PM, said:

View PosttheRemix, on 12 Mar, 2009 - 10:04 PM, said:

back when i did. i would put all the instances(movieclips) that are referenced in your document class on the stage on frame 1. then where you need it placed (frame 2) make it a keyframe.


What do you mean with "make it a keyframe"?

Now I'm struggling with how to structure the navigation a decent way for 15 questions.
When the "Check result" button is clicked, some code is checking which radiobuttons is chosen and then add values to certain variables. All the questions have to be at frame 1 for it to work, because the code is in the Document Class.

The way I'm doing it now, I'll have to use alot of next-buttons and previous-buttons... which is pretty time consuming. Wish I could do this with one next-button and one previous-button.


i don't know how it's structured now, but, you can use the same next back buttons and just swap in the movieclips in sequence

if you named each of those 'invisible' movieclips (questions i guess)
like question_0, question_1, question_2, etc..
then make a counter
var cur_question:int = 0;

then on next button do
//hide current question
this["question_"+cur_question].alpha = 0;
this["question_"+cur_question].x = 999;

//increment
cur_question++;

//show next question
this["question_"+cur_question].alpha = 1;
this["question_"+cur_question].x = 0;


then decrement for previous question

hope this makes sense, this is a quick way, but prone to errors.

a better way would be to store each "question" movieclip in an array, and access them that way.

hth
Was This Post Helpful? 0
  • +
  • -

#6 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: MovieClips on different frames - actionscript issues (Flash CS3, AS3)

Posted 26 April 2009 - 01:12 PM

I donīt know quite understand what you are doing here people...
So, I think that you have the "Next" button on every (except the last question) and it is in the same position, right?
So, that way, you donīt need to create keyframes of that button for all of these 15 questions (14 resp.), you can just do one keyframe which is 14 frames long. In that frame, there is a button, which has the script:
on (release){
 _root.nextFrame();
}


on it.
So, this button is in one layer called "button", your questions are in a separated layer "questions"... And the check button is in the "button" layer too, but in another keyframe on 15.

Oh and btw... these buttons are buttons... :P not MCs.

This post has been edited by Aurel300: 26 April 2009 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1