ForumsProgramming ForumAnyone Wanna Help me improve my code?

23 14607
cheese123
offline
cheese123
20 posts
Nomad

So I am a newb at flash and you guys seem reasonably nice (compared to some other places)

So I was wandering if you were willing to help. I appreciate the help of anyone but to the experienced programmers - please don't laugh if my code looks stupid.

Anyway thanks for reading.

  • 23 Replies
strouthas
offline
strouthas
24 posts
Nomad

Any specific question?

cheese123
offline
cheese123
20 posts
Nomad

Yea I do have one.

In a point and click game what is the best way to speak to characters? I have thought about adding another frame in the character and a bunch of movie clip buttons but I don't really like this idea.

Then maybe just a uniform dialogue movie clip (a blank square) that attaches to the scene when you click a character and fills up with dialogue. Then it unloads once you are done. This method seems like it could get messy when coding. I was thinking maybe an array to store dialogues of the different characters, another array to store the unique button labels (like hello) for each character. But maybe its over complicated?

I think the first method is just better because it's the simple solution, but something tells me that both these ideas are bad.

cheese123
offline
cheese123
20 posts
Nomad

I don't like the first idea because imagine all the movie clips you'll need. It seems like a waste.

boppins
offline
boppins
774 posts
Bard

Kind of hard to get a picture of what you need -- got any screenshots?

A point and click game could be a few things. Is it a static screen with things to click on like Myst? Or is it more like Monkey Island where you click and your character moves?

I think both solutions sound okay. Do what is easy and easy to maintain (and doesn't hurt performance).

weirdlike
offline
weirdlike
1,299 posts
Prince

You can't improve on nothing.... also coding is very tedious you can try doing this

Remember 1 frame 1 action layer as noted here

Insert a new layer labeled dialogue. Create the talking bubble or square, create 2 if you have another person talking.

Then click on the keyframe and highlight it, modify>convert to symbol.

Converting the keyframe to a symbol (and don't forget to name the instance) instead of the object itself makes it a separate video to play within the main (root) timeline.

At this point you can control the conversation

function mouseClick1(event:MouseEvent):void
{
trace("Mouse clicked mouseClick1"
dialogueBox.gotoAndStop(1);
}
....
dialogueBox.gotoAndStop(2);
dialogueBox.gotoAndStop(3);
....

Then you can keep control of the conversation by adding an additional layer on the newly created symbol and giving a label name like "hello" and "bye"
...
dialogueBox.gotoAndStop("hello"
dialogueBox.gotoAndStop("bye"
...

there may be a better way to do this but this one works for me

DEMO

fla

links above will break at any time...

weirdlike
offline
weirdlike
1,299 posts
Prince

sorry if my previous post seems too aggressive no offense intended, it was actually longer and I edited it to make less reading

strouthas
offline
strouthas
24 posts
Nomad

What I prefer most, is a class injecting a semi transparent frame on top of the display list, holding the text you want. You can have properties about the alpha amount, the font to be used, the window size of the frame etc. Now, whenever you need the dialogue displayed you just call the show method of the class, passing the resource id (if you have all the dialogs in an XML) or the text itself.

cheese123
offline
cheese123
20 posts
Nomad

@ boppins - just a black box on the screen with the same 3 dialogue buttons (which change labels depending on who you click)
@weirdlike - that seems closer to my first solution
@strouthas - i know nothing about classes

- thanks!

weirdlike
offline
weirdlike
1,299 posts
Prince

have you tried this, I used arial as the font

var format:TextFormat = new TextFormat();
var myFont:Font = new Arial ();
format.font = myFont.fontName;
message_txt.defaultTextFormat = format;
message_txt.text = "You awake from sleeping...";

message_txt.addEventListener(MouseEvent.CLICK, mouseClick);

function mouseClick(event:MouseEvent):void
{
trace("Mouse clicked"
message_txt.text = "you feel sick";
message_txt.removeEventListener(MouseEvent.CLICK, mouseClick);
message_txt.addEventListener(MouseEvent.CLICK, cont);
function cont(event:MouseEvent):void
{
trace("Mouse clicked2"
message_txt.text = &quoterhaps too much to drink...";
message_txt.removeEventListener(MouseEvent.CLICK, cont);
}
}

same demo link as above click refresh page
new fla example here

cheese123
offline
cheese123
20 posts
Nomad

Oh are you using AS3? Im still in the dark ages with AS2

weirdlike
offline
weirdlike
1,299 posts
Prince

var format:TextFormat = new TextFormat();
format.font = "Arial";

label.text = "You awake from sleeping...";

label.onMouseDown=function(evt)
{
trace("myListener1"
label.text = "you feel sick";

label.onMouseDown=function(evt)
{
trace("myListener2"
label.text = &quoterhaps too much to drink...";
}
}


fla

cheese123
offline
cheese123
20 posts
Nomad

Also.. Whenever I pick up an object it unloads the movie clip (that was the object)
When I go back to the original scene that object comes back.

To counter this I decided to have all my scenes on one frame, and move the whole scene by about 500px when I click an arrow to go somewhere else. I realized that this could hurt performance?

Do you think when I pick an object, I can push values into an array. Depending on what values the array contains, it removes the object from the scene, and each time I go back to a frame it checks all the values and removes objects accordingly.

weirdlike
offline
weirdlike
1,299 posts
Prince

additional frames are kinda not good but you can try this

on the first frame add

var box:Boolean = true;

on the 2nd frame (or whichever) check if it is true

if (box)
{
trace("box true"
//true function here
}
else
{
trace("box false"
box.visible = false;
//function here
}

don't forget to add the trigger that makes it false so the box is hidden the second time around and the var is on the first frame so it only gets changed through actionscript

also this is 3.0 sorry but it might help a little

cheese123
offline
cheese123
20 posts
Nomad

no worries, i understand what your saying

yea i thought about that idea, but then you need to add a variable for each item. might get a bit cluttered right?

weirdlike
offline
weirdlike
1,299 posts
Prince

I suppose so, if you wanted one visible and the another invisible you would need a separate variable for it to work, you can also check to see if it is false so if you wanted one visible while the other is invisible and vise versa

Showing 1-15 of 23