a more effective way to write this ?
Hi all,
Lately i've been trying to right in external classfiles to create everything and make everything work instead of stuffing everything in my timeline.
So now i have made a classfile that first creates all the movieclips i wan't on the stage and then defines what all the buttons do.
But when i want to acces a variable that has been created in "createMc" from a private function i get an error, so i have fixed this by giving the var's a name and then use getChildByName().
But i think this looks like a really innificiant way off writing something and was wondering if it was possible to write this in a better, shorter, and thus more effective way. Any ideas ?
Grts !
Here's the code:
package {
import flash.display.MovieClip;
import flash.events.*;
public class createMc extends MovieClip {
public function createMc() {
var home:homeMc = new homeMc();
home.x = 400;
home.y = 265;
addChild(home);
home.name = "homeGeb";
var contact:contactMc = new contactMc();
contact.x = 400;
contact.y = 265;
addChild(contact);
contact.visible = false;
contact.name = "contGeb";
var info:infoMc = new infoMc();
info.x = 400;
info.y = 265;
addChild(info);
info.visible = false;
info.name = "infoGeb";
var imp:impsMc = new impsMc();
imp.x = 400;
imp.y = 265;
addChild(imp);
addChild(imp);
imp.visible = false;
imp.name = "impGeb";
var mulKnop:mulKnopMc = new mulKnopMc();
mulKnop.x = 400;
mulKnop.y = 50;
mulKnop.buttonMode = true;
addChild(mulKnop);
var homeBtn:homeKnopMc = new homeKnopMc();
homeBtn.x = 179.15;
homeBtn.y = 569.5;
homeBtn.buttonMode = true;
addChild(homeBtn);
var impBtn:impsKnopMc = new impsKnopMc();
impBtn.x = 293.3;
impBtn.y = 569.5;
impBtn.buttonMode = true;
addChild(impBtn);
var infBtn:infoKnopMc = new infoKnopMc();
infBtn.x = 452.7;
infBtn.y = 569.5;
infBtn.buttonMode = true;
addChild(infBtn);
var contBtn:contKnopMc = new contKnopMc();
contBtn.x = 574.2;
contBtn.y = 569.5;
contBtn.buttonMode = true;
addChild(contBtn);
homeBtn.addEventListener(MouseEvent.CLICK, homeClick);
impBtn.addEventListener(MouseEvent.CLICK, impClick);
infBtn.addEventListener(MouseEvent.CLICK, infClick);
contBtn.addEventListener(MouseEvent.CLICK, contClick);
}
private function homeClick(evt:MouseEvent):void {
trace("geklikt");
var home: MovieClip = MovieClip(getChildByName("homeGeb"));
var imps: MovieClip = MovieClip(getChildByName("impGeb"));
var info: MovieClip = MovieClip(getChildByName("infoGeb"));
var contact: MovieClip = MovieClip(getChildByName("contGeb"));
home.visible = true;
imps.visible = false;
info.visible = false;
contact.visible = false;
}
private function impClick(evt:MouseEvent):void {
trace("geklikt");
var home: MovieClip = MovieClip(getChildByName("homeGeb"));
var imps: MovieClip = MovieClip(getChildByName("impGeb"));
var info: MovieClip = MovieClip(getChildByName("infoGeb"));
var contact: MovieClip = MovieClip(getChildByName("contGeb"));
home.visible = false;
imps.visible = true;
info.visible = false;
contact.visible = false;
}
private function infClick(evt:MouseEvent):void {
trace("geklikt");
var home: MovieClip = MovieClip(getChildByName("homeGeb"));
var imps: MovieClip = MovieClip(getChildByName("impGeb"));
var info: MovieClip = MovieClip(getChildByName("infoGeb"));
var contact: MovieClip = MovieClip(getChildByName("contGeb"));
home.visible = false;
imps.visible = false;
info.visible = true;
contact.visible = false;
}
private function contClick(evt:MouseEvent):void {
trace("geklikt");
var home: MovieClip = MovieClip(getChildByName("homeGeb"));
var imps: MovieClip = MovieClip(getChildByName("impGeb"));
var info: MovieClip = MovieClip(getChildByName("infoGeb"));
var contact: MovieClip = MovieClip(getChildByName("contGeb"));
home.visible = false;
imps.visible = false;
info.visible = false;
contact.visible = true;
}
}
}
And yet another question:
I have created this: http://semagames.be/testplaats/portHome.swf
Practically without any code (just using the bone tool for the movement of the strings).
But what i want now is that when you lift up the strings and release them is that they under influence of the gravity swing back to their original places. Just like a pendulum or something like that.
How can that be achieved ?
Grts !