The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 1:57 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 2 posts ] 
[Request] Second button disapearing of the stage. 
Author Message

Joined: Thu Nov 18, 2010 3:42 pm
Posts: 3
Gender: Anime Girl
I've been making a simple RPG battle system so I could use some parts of the code in a serious RPG after, but when I was making a certain part (more details below) of the code I've run on a problem with the code that I can't figure out the solution. Basically, when I go from the frame managing the battle to the frame where I'm adding the battle options, the second button that I put there disapears, It doesn't need to have a code refering to it or even an instance name.

Since I couldn't find any leads on google or on the McLeodGaming search (I used key words related with "Object on stage disapears") and couldn't find the souce of the problem on my code, I decided to make a copy of the file and "trim" the code so I could reproduce the problem with as few code as possible. It turned out like this:

Layer 1, Frame 1: A blank keyframe with a code to find the stage center.
Code:
function StgCenter(){
   var i:Point = new Point(stage.stageWidth/2,stage.stageHeight/2)
   return(i)
}


Layer 2, Frame 1: Another blank keyframe with a variable defined for adding an object from the library later.
Code:
var Bat_Sel = new BatSel


Layer 2, Frame 2: Blank keyframe without code (I tryed to trim the code without change the frames, so I left this one without the code, but didn't deleted it)

Layer 2, Frame 3: Key frame with an "Enter" button called EnterButton on it and coding to go to the main frame.
Code:
EnterButton.addEventListener(MouseEvent.CLICK,StartGame)

stop()

function StartGame(MouseEvent){
   gotoAndStop("StartFr")
}


Layer 2, Frame 4 (Called "StartFr"): Keyframe with a "Test Battle" button called TestBattle and a blank button. Since the blank button is the second button that I put on stage, it is the one who disapears. Alse, there is a code to go to the battle frame.
Code:
removeEventListener(Event.ENTER_FRAME,BattleFunction)
TestBattle.addEventListener(MouseEvent.CLICK,TestBattleSource)
removeChild(Bat_Sel)

function TestBattleSource(MouseEvent){
   gotoAndStop("BattleFr")
}


Layer 2, Frame 4 (Called "BattleFr"): Key frame with a dynamic text field called BatText. Since I wanted to have a well established battle before adding graphics and sounds, I just gone with text based battle until then, but it turned out that when I delete this text field, the second button stays there, so I think the answer lies there. Also there is an important part of the code.
Code:
addEventListener(Event.ENTER_FRAME,BattleFunction)

var BtCurP:Number=0
var BtSelP:Number=0

function BattleFunction(Event){
   if(BtCurP==0){
      BtCurP++
   }
   if(BtCurP==1){
      if(BtSelP==0){
         MovieClip(root).addChild(Bat_Sel) //Causa erro. (Por quĂȘ?)
         Bat_Sel.width=550-4
         Bat_Sel.height=(400-277)-6
         Bat_Sel.x=StgCenter().x
         Bat_Sel.y=277+((400-277)/2)
         BtSelP++
      }
   }
}

The comment on line 12 translates to "Causes error. Why?" and it was a note to myself that I decided not to erase from the trimmed file. Also, as happened with the textfield, if you delete this line, the button stays there.

BatSel: Last, but not least, the movieclip Called BatSel on library, exported for actionscript on frame 1, with class name BatSel and base class flash.display.MovieClip. Inside it there are 4 buttons, one of them named BButton4 and the frame one (the only) of the movie clip has an script to go back to the main frame.
Code:
BButton4.addEventListener(MouseEvent.CLICK,SetBatOption4)
function SetBatOption4(MouseEvent){
   MovieClip(root).gotoAndStop("StartFr")
}


I'll also leave the trimmed file attached here, if some one want to give a look, which I nicknamed "Debugger". If you need me to explain anything else, just tell me. If someone could at least give a lead of what is going on I would be grateful.


Attachments:
File comment: Trimmed code, enough to reproduce my problem.
Debugger.rar [10.95 KiB]
Downloaded 133 times
Wed Feb 19, 2014 3:45 pm

Joined: Thu Nov 18, 2010 3:42 pm
Posts: 3
Gender: Anime Girl
Nevermind, I fixed it. Just moved the RemoveChild on frame 4 and the gotoAndStop on the movieClip to frame 5 under the condition BtSelP==3 and the BButton4 now does a BtSelP++ command on root. Not only fixed the disapearing button, but also fixed the error that it gave when there were no childs on stage.


Thu Feb 20, 2014 7:36 am
Display posts from previous:  Sort by  
 [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.