03.05.2013 Views

Tutorial: Jigsaw using ActionScript 3.0.

Tutorial: Jigsaw using ActionScript 3.0.

Tutorial: Jigsaw using ActionScript 3.0.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

import jigsawauto.*;<br />

I renamed the Text Field instructions. This was not necessary, but I thought it was<br />

a better name since that is how the field is used initially.<br />

Save the .fla file as lizardauto.fla. This can be saved in the same folder as<br />

lizardplain.fla.<br />

Next, open up the Piece.as file. I then saved this file by going to c:\as3 and creating a<br />

new folder called jigsawauto. Save Piece.as in this folder. Note that this means<br />

you do not need to change or add to the classpath for lizardauto. It is the same as<br />

lizardplain. [Of course, I am not forcing the name lizard on you. You can name the<br />

.fla file whatever you want. Since, hopefully, your initial one is working, I would save<br />

the new one with a different name.]<br />

This code refers to the TextField datatype, so you need to add the statement<br />

import flash.text.*;<br />

to the import statements at the start of the Piece file.<br />

In the Piece.as file, look at the stopdragging method. This is where I will put the code to<br />

call checkit. I change the header for checkit to have the internal modifier, since it is<br />

no longer called from outside the class.<br />

internal static function checkit():Boolean {<br />

The idea that did not work was to have the stopdragging method create a Text Field<br />

dynamically. This is possible, but it is necessary to do what is called add the Text Field to<br />

the display list and there is not a good candidate. This is chiefly for security reasons. So<br />

in order to provide a place to write the "Good Job", what I do is have the mixup method<br />

pass in the name of the text field already on the board:<br />

Piece.mixup(instructions);<br />

instructions.text=<br />

"Use mouse to drag&drop. With mouse down, use arrows to rotate"<br />

When you make this change, be sure and save the .fla file again.<br />

Now, back to Piece.as, add a new class variable:<br />

internal static var res:TextField;<br />

Change the header and the statement to mixup:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!