Zdravím,
potřeboval bych poradit s kódem. Píšu nějáký ten pátek amatérskou "hru"
a všechno zatím jakž takž jde, ale mám problém s tím že na hlavním
FRAMu, je kód zřejmě příliš dlouhý a flash od určité délky v debuggeru
zamrzá.
Konkrétně mám na framu spoustu Movieclipů u kterých měním jejich
viditelnost pak nějáký ten časovač a pár podmínek typu if/else a funkce
na kliknutí myší nahrazujících tlačítka. Vím že to bude asi dost
prasácky napsané no jsem v programování amatér, ale byl bych rád kdyby
jste mi pomohli najít něco co by mi pomohlo zmenšit náročnost aplikace, tak
abych nebyl nucen těsně před cílem skončit. Díky.
Zde je kód 4tého hlavního framu:
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
if (pavelON == true) {
pavel2.visible = true;
} else {
pavel2.visible = false;
}
if (petrON == true) {
petr2.visible = true;
} else {
petr2.visible = false;
}
if (martinON == true) {
martin2.visible = true;
} else {
martin2.visible = false;
}
if (zdencaON == true) {
zdenca2.visible = true;
} else {
zdenca2.visible = false;
}
if (danON == true) {
dan2.visible = true;
} else {
dan2.visible = false;
}
if (paziON == true) {
pazi2.visible = true;
} else {
pazi2.visible = false;
}
var countDownDec:Number = 1;
var totalSecs = 0;
var countDownSecs = totalSecs;
cas.text = countDownSecs;
var time:Timer = new Timer(countDownDec*1000);
time.addEventListener(TimerEvent.TIMER, tick);
function tick(e:TimerEvent):void {
if (countDownSecs == 120) {
trace("count down complete");
time.stop();
countDownSecs = totalSecs;
} else {
countDownSecs = countDownSecs + countDownDec;
cas.text = countDownSecs;
}
}
stage.addEventListener(Event.ENTER_FRAME, startTimer);
function startTimer(e:Event):void {
if(time.running == true) {
} else {
cas.text = totalSecs;
time.start();
}
}
var mcnm:Number = 2;
var mcnf:Number = 0;
var mcnt:Number = 0;
var hm:Number = 0;
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
pavel2.stop();
petr2.stop();
martin2.stop();
zdenca2.stop();
dan2.stop();
pazi2.stop();
pavel_prace.visible = false;
petr_prace.visible = false;
martin_prace.visible = false;
zdenca_prace.visible = false;
dan_prace.visible = false;
pazi_prace.visible = false;
upozorneni.visible = false;
var pavel2ON:Boolean = false;
var petr2ON:Boolean = false;
var martin2ON:Boolean = false;
var zdenca2ON:Boolean = false;
var dan2ON:Boolean = false;
var pazi2ON:Boolean = false;
upozorneni.zavrit.addEventListener(MouseEvent.CLICK,zavriClick);
function zavriClick(event:MouseEvent):void{
upozorneni.visible = false;}
pavel2.addEventListener(MouseEvent.CLICK,pavelClick);
function pavelClick(event:MouseEvent):void{
if ((pavel2ON == false)&&(mcnm > 0)){
pavel_prace.visible = true;
pavel_prace.pavel_volba1.addEventListener(MouseEvent.CLICK,pav1Click);
function pav1Click(event:MouseEvent):void{
pavel_prace.visible = false;
pavel2.play();
pavel2ON = true;
setTimeout(timedFunction1,10000);
function timedFunction1() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
pavel2ON = false;
pavel2.stop();}
}
pavel_prace.pavel_volba2.addEventListener(MouseEvent.CLICK,pav2Click);
function pav2Click(event:MouseEvent):void{
pavel_prace.visible = false;
pavel2.play();
pavel2ON = true;
setTimeout(timedFunction2,3000);
function timedFunction2() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
pavel2ON = false;
pavel2.stop();}
}
pavel_prace.pavel_volba3.addEventListener(MouseEvent.CLICK,pav3Click);
function pav3Click(event:MouseEvent):void{
pavel_prace.visible = false;
pavel2.play();
pavel2ON = true;
setTimeout(timedFunction3,5000);
function timedFunction3() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
pavel2ON = false;
pavel2.stop();
}
}
}
if (mcnm > 0){
mcnm--;
mcnf++}
else {
pavel_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Pavel nemá motory na montáž!"
pavel2.stop();
pavel2ON = false;
setTimeout(timedFunction4,4000);
function timedFunction4() {
upozorneni.visible = false;}
}
}
petr2.addEventListener(MouseEvent.CLICK,petrClick);
function petrClick(event:MouseEvent):void{
if ((petr2ON == false)&&(mcnm > 0)){
petr_prace.visible = true;
petr_prace.petr_volba1.addEventListener(MouseEvent.CLICK,pet1Click);
function pet1Click(event:MouseEvent):void{
petr_prace.visible = false;
petr2.play();
petr2ON = true;
setTimeout(timedFunction1,10000);
function timedFunction1() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
petr2ON = false;
petr2.stop();
}
}
petr_prace.petr_volba2.addEventListener(MouseEvent.CLICK,pet2Click);
function pet2Click(event:MouseEvent):void{
petr_prace.visible = false;
petr2.play();
petr2ON = true;
setTimeout(timedFunction2,5000);
function timedFunction2() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
petr2ON = false;
petr2.stop();
}
}
petr_prace.petr_volba3.addEventListener(MouseEvent.CLICK,pet3Click);
function pet3Click(event:MouseEvent):void{
petr_prace.visible = false;
petr2.play();
petr2ON = true;
setTimeout(timedFunction3,3000);
function timedFunction3() {
mcnmt.text = mcnm.toString();
mcnft.text = mcnf.toString();
petr2ON = false;
petr2.stop();}
}
}
if (mcnm > 0){
mcnm--;
mcnf++}
else {
petr_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Petr nemá motory na montáž!"
petr2.stop();
petr2ON = false;
setTimeout(timedFunction5,4000);
function timedFunction5() {
upozorneni.visible = false;}
}
}
martin2.addEventListener(MouseEvent.CLICK,martinClick);
function martinClick(event:MouseEvent):void{
if ((martin2ON == false)&&(mcnf > 0)) {
martin_prace.visible = true;
martin_prace.martin_volba1.addEventListener(MouseEvent.CLICK,m1Click);
function m1Click(event:MouseEvent):void{
martin_prace.visible = false;
martin2.play();
martin2ON = true;
setTimeout(timedFunction1,3000);
function timedFunction1() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
martin2ON = false;
martin2.stop();}
}
martin_prace.martin_volba2.addEventListener(MouseEvent.CLICK,m2Click);
function m2Click(event:MouseEvent):void{
martin_prace.visible = false;
martin2.play();
martin2ON = true;
setTimeout(timedFunction2,10000);
function timedFunction2() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
martin2ON = false;
martin2.stop();}
}
martin_prace.martin_volba3.addEventListener(MouseEvent.CLICK,m3Click);
function m3Click(event:MouseEvent):void{
martin_prace.visible = false;
martin2.play();
martin2ON = true;
setTimeout(timedFunction3,5000);
function timedFunction3() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
martin2ON = false;
martin2.stop();}
}
}
if (mcnf > 0){
mcnf--;
mcnt++;}
else {
martin_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Martin nemá motory na montáž!"
martin2.stop();
martin2ON = false;
setTimeout(timedFunction6,4000);
function timedFunction6() {
upozorneni.visible = false;}
}
}
zdenca2.addEventListener(MouseEvent.CLICK,zdeClick);
function zdeClick(event:MouseEvent):void{
if ((zdenca2ON == false)&&(mcnf > 0)) {
zdenca_prace.visible = true;
zdenca_prace.zdenca_volba1.addEventListener(MouseEvent.CLICK,z1Click);
function z1Click(event:MouseEvent):void{
zdenca_prace.visible = false;
zdenca2.play();
zdenca2ON = true;
setTimeout(timedFunction1,3000);
function timedFunction1() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
zdenca2ON = false;
zdenca2.stop();}
}
zdenca_prace.zdenca_volba2.addEventListener(MouseEvent.CLICK,z2Click);
function z2Click(event:MouseEvent):void{
zdenca_prace.visible = false;
zdenca2.play();
zdenca2ON = true;
setTimeout(timedFunction2,10000);
function timedFunction2() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
zdenca2ON = false;
zdenca2.stop();}
}
zdenca_prace.zdenca_volba3.addEventListener(MouseEvent.CLICK,z3Click);
function z3Click(event:MouseEvent):void{
zdenca_prace.visible = false;
zdenca2.play();
zdenca2ON = true;
setTimeout(timedFunction3,5000);
function timedFunction3() {
mcnft.text = mcnf.toString();
mcntt.text = mcnt.toString();
zdenca2ON = false;
zdenca2.stop();}
}
}
if (mcnf > 0){
mcnf--;
mcnt++;}
else {
zdenca_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Zdenča nemá motory na montáž!"
zdenca2.stop();
zdenca2ON = false;
setTimeout(timedFunction7,4000);
function timedFunction7() {
upozorneni.visible = false;}
}
}
dan2.addEventListener(MouseEvent.CLICK,danClick);
function danClick(event:MouseEvent):void{
if ((dan2ON == false)&&(mcnt > 0)) {
dan_prace.visible = true;
dan_prace.dan_volba1.addEventListener(MouseEvent.CLICK,d1Click);
function d1Click(event:MouseEvent):void{
dan_prace.visible = false;
dan2.play();
dan2ON = true;
setTimeout(timedFunction1,10000);
function timedFunction1() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
dan2ON = false;
dan2.stop();}
}
dan_prace.dan_volba2.addEventListener(MouseEvent.CLICK,d2Click);
function d2Click(event:MouseEvent):void{
dan_prace.visible = false;
dan2.play();
dan2ON = true;
setTimeout(timedFunction2,5000);
function timedFunction2() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
dan2ON = false;
dan2.stop();}
}
dan_prace.dan_volba3.addEventListener(MouseEvent.CLICK,d3Click);
function d3Click(event:MouseEvent):void{
dan_prace.visible = false;
dan2.play();
dan2ON = true;
setTimeout(timedFunction3,3000);
function timedFunction3() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
dan2ON = false;
dan2.stop();}
}
}
if (mcnt > 0){
mcnt--;
hm++;}
else {
dan_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Dan nemá motory na test!"
dan2.stop();
dan2ON = false;
setTimeout(timedFunction8,4000);
function timedFunction8() {
upozorneni.visible = false;}
}
}
/*
pazi2.addEventListener(MouseEvent.CLICK,pazClick);
function pazClick(event:MouseEvent):void{
if ((pazi2ON == false)&&(mcnt > 0)) {
pazi_prace.visible = true;
pazi_prace.pazi_volba1.addEventListener(MouseEvent.CLICK,paz1Click);
function paz1Click(event:MouseEvent):void{
pazi_prace.visible = false;
pazi2.play();
pazi2ON = true;
setTimeout(timedFunction1,10000);
function timedFunction1() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
pazi2ON = false;
pazi2.stop();}
}
pazi_prace.pazi_volba2.addEventListener(MouseEvent.CLICK,paz2Click);
function paz2Click(event:MouseEvent):void{
pazi_prace.visible = false;
pazi2.play();
pazi2ON = true;
setTimeout(timedFunction2,5000);
function timedFunction2() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
pazi2ON = false;
pazi2.stop();}
}
pazi_prace.pazi_volba3.addEventListener(MouseEvent.CLICK,paz3Click);
function paz3Click(event:MouseEvent):void{
pazi_prace.visible = false;
pazi2.play();
pazi2ON = true;
setTimeout(timedFunction3,3000);
function timedFunction3() {
mcntt.text = mcnt.toString();
hmt.text = hm.toString();
pazi2ON = false;
pazi2.stop();}
}
}
if (mcnt > 0){
mcnt--;
hm++;}
else {
pazi_prace.visible = false;
upozorneni.visible = true;
upozorneni.upoz_text.text = "Pazi nemá motory na test!"
pazi2.stop();
pazi2ON = false;
setTimeout(timedFunction9,4000);
function timedFunction9() {
upozorneni.visible = false;}
}
}
Přikládám i soubor swf aby jste viděli funkci. https://ulozto.cz/…lmorgen3-swf (pass: " pomoc " )
Ten konec mám v závorkách úmyslně, protože bez nich už to zamrzá.
Neznám limity Adobe Flashe CS5.5.
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.