Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-06-2012, 10:06 PM   #1
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Default Taking One Value From Frame And Displaying It In Another Frame

Hi.. Please Help

ii have two values in frame two that ii want to display in frame 3 how do ii do this ii have already written some code but unsure if it is correct...

well it doesn't work as the values don't actually show up.

Frame 2 Coding:

ActionScript Code:
var game:XML; var Characters1:MovieClip; var Characters2:MovieClip; var C1 = Math.floor(Math.random()*(1+8-2))+2; var C2 = Math.floor(Math.random()*(1+8-2))+2; var CName1 = C1 - 2; var CName2 = C2 - 2; generatecharacterbox(); var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); loader.load(new URLRequest("game.xml")); var numGoes:Number = 10; addEventListener(Event.ENTER_FRAME, numCount); function numCount(event:Event) {         if(numGoes == 0)     {         gotoAndStop(3);     } } function onComplete(evt:Event):void {     try     {         game = new XML(evt.target.data);         readByName();         loader.removeEventListener(Event.COMPLETE, onComplete);         loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);     }     catch (err:Error)     {         trace("Could not parse loaded content as XML:\n" + err.message);     } } function onIOError(evt:IOErrorEvent):void {     trace("an error ocured when attempting to load the XML.\n" + evt.text); } function readByName() {     //trace(game.cards);     //trace(game.cards.card.name);     //trace(game.cards.card.name[0]);     //trace(game..name);     //trace(game..card);     //trace(game..card.*);     //trace(game.title);     //trace(game.title.nodeKind());     trace(C1);     trace(C2);         C1 = Math.floor(Math.random()*(1+8-2))+2;     C2 = Math.floor(Math.random()*(1+8-2))+2;     CName1 = C1 - 2;     CName2 = C2 - 2;         Characters1.gotoAndStop(C1);     Characters2.gotoAndStop(C2);     CharactersName1.text = String(game.cards.card.name[CName1]);     CharactersName2.text = String(game.cards.card.name[CName2]);     attack1.text = String(game.cards.card.attack[CName1]);     attack2.text = String(game.cards.card.attack[CName2]);     damages1.text = String(game.cards.card.damages[CName1]);     damages2.text = String(game.cards.card.damages[CName2]); } function generatecharacterbox() {     Characters1 = new Pokemonbox();     Characters1.x = 140;     Characters1.y = 150;     stage.addChild(Characters1);     Characters2 = new Pokemonbox();     Characters2.x = 410;     Characters2.y = 150;     stage.addChild(Characters2); } myButton.addEventListener(MouseEvent.MOUSE_UP,checkValue); function checkValue(event:MouseEvent):void {         numGoes--;         var playerScore = int(playerScoreScreen.text);     var computerScore = int(computerScoreScreen.text);     if (game.cards.card.damages[CName1] == game.cards.card.damages[CName2])     {         winner.text = "Draw";         trace("Draw");     }     else if (game.cards.card.damages[CName1] > game.cards.card.damages[CName2])     {         playerScore++;         winner.text = "Player Wins";                 trace("Player Wins");     }     else     {         computerScore++;         winner.text = "Computer Wins";                 trace("Computer Wins");     }     trace(computerScore);     trace(playerScore);         playerScoreScreen.text = playerScore.toString();     computerScoreScreen.text = computerScore.toString();     goesLeft.text = numGoes.toString(); } GenerateCards.addEventListener(MouseEvent.CLICK,generation); function generation(event:MouseEvent) {     readByName(); } stop();

Frame 3 Coding:

ActionScript Code:
stage.removeChild(Characters1); stage.removeChild(Characters2); playerFinalScore.text = playerScoreScreen.toString(); computerFinalScore.text = computerScoreScreen.toString();

Thanks in advance to any responds.
AnimatedCircle is offline   Reply With Quote
Old 04-07-2012, 11:35 AM   #2
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Default One Value From Text Box To Another Text Box

Hi.. Please Help

ii have two values in frame two that ii want to display in frame 3 how do ii do this ii have already written some code but unsure if it is correct...

well it doesn't work as the values don't actually show up.

Frame 2 Coding:

ActionScript Code:
var game:XML; var Characters1:MovieClip; var Characters2:MovieClip; var C1 = Math.floor(Math.random()*(1+8-2))+2; var C2 = Math.floor(Math.random()*(1+8-2))+2; var CName1 = C1 - 2; var CName2 = C2 - 2; generatecharacterbox(); var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); loader.load(new URLRequest("game.xml")); var numGoes:Number = 10; addEventListener(Event.ENTER_FRAME, numCount); function numCount(event:Event) {         if(numGoes == 0)     {         gotoAndStop(3);     } } function onComplete(evt:Event):void {     try     {         game = new XML(evt.target.data);         readByName();         loader.removeEventListener(Event.COMPLETE, onComplete);         loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);     }     catch (err:Error)     {         trace("Could not parse loaded content as XML:\n" + err.message);     } } function onIOError(evt:IOErrorEvent):void {     trace("an error ocured when attempting to load the XML.\n" + evt.text); } function readByName() {     //trace(game.cards);     //trace(game.cards.card.name);     //trace(game.cards.card.name[0]);     //trace(game..name);     //trace(game..card);     //trace(game..card.*);     //trace(game.title);     //trace(game.title.nodeKind());     trace(C1);     trace(C2);         C1 = Math.floor(Math.random()*(1+8-2))+2;     C2 = Math.floor(Math.random()*(1+8-2))+2;     CName1 = C1 - 2;     CName2 = C2 - 2;         Characters1.gotoAndStop(C1);     Characters2.gotoAndStop(C2);     CharactersName1.text = String(game.cards.card.name[CName1]);     CharactersName2.text = String(game.cards.card.name[CName2]);     attack1.text = String(game.cards.card.attack[CName1]);     attack2.text = String(game.cards.card.attack[CName2]);     damages1.text = String(game.cards.card.damages[CName1]);     damages2.text = String(game.cards.card.damages[CName2]); } function generatecharacterbox() {     Characters1 = new Pokemonbox();     Characters1.x = 140;     Characters1.y = 150;     stage.addChild(Characters1);     Characters2 = new Pokemonbox();     Characters2.x = 410;     Characters2.y = 150;     stage.addChild(Characters2); } myButton.addEventListener(MouseEvent.MOUSE_UP,checkValue); function checkValue(event:MouseEvent):void {         numGoes--;         var playerScore = int(playerScoreScreen.text);     var computerScore = int(computerScoreScreen.text);     if (game.cards.card.damages[CName1] == game.cards.card.damages[CName2])     {         winner.text = "Draw";         trace("Draw");     }     else if (game.cards.card.damages[CName1] > game.cards.card.damages[CName2])     {         playerScore++;         winner.text = "Player Wins";                 trace("Player Wins");     }     else     {         computerScore++;         winner.text = "Computer Wins";                 trace("Computer Wins");     }     trace(computerScore);     trace(playerScore);         playerScoreScreen.text = playerScore.toString();     computerScoreScreen.text = computerScore.toString();     goesLeft.text = numGoes.toString(); } GenerateCards.addEventListener(MouseEvent.CLICK,generation); function generation(event:MouseEvent) {     readByName(); } stop();

Frame 3 Coding:

ActionScript Code:
stage.removeChild(Characters1); stage.removeChild(Characters2); playerFinalScore.text = playerScoreScreen.toString(); computerFinalScore.text = computerScoreScreen.toString();

Thanks in advance to any responds.
AnimatedCircle is offline   Reply With Quote
Old 04-07-2012, 06:05 PM   #3
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Question Dynamic Text Box Value From One To Another

Hi.. Please Help

ii have two values in frame two that ii want to display in frame 3 how do ii do this ii have already written some code but unsure if it is correct...

well it doesn't work as the values don't actually show up.

Frame 2 Coding:

ActionScript Code:
ActionScript Code: var game:XML; var Characters1:MovieClip; var Characters2:MovieClip; var C1 = Math.floor(Math.random()*(1+8-2))+2; var C2 = Math.floor(Math.random()*(1+8-2))+2; var CName1 = C1 - 2; var CName2 = C2 - 2; generatecharacterbox(); var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); loader.load(new URLRequest("game.xml")); var numGoes:Number = 10; addEventListener(Event.ENTER_FRAME, numCount); function numCount(event:Event) {         if(numGoes == 0)     {         gotoAndStop(3);     } } function onComplete(evt:Event):void {     try     {         game = new XML(evt.target.data);         readByName();         loader.removeEventListener(Event.COMPLETE, onComplete);         loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);     }     catch (err:Error)     {         trace("Could not parse loaded content as XML:\n" + err.message);     } } function onIOError(evt:IOErrorEvent):void {     trace("an error ocured when attempting to load the XML.\n" + evt.text); } function readByName() {     //trace(game.cards);     //trace(game.cards.card.name);     //trace(game.cards.card.name[0]);     //trace(game..name);     //trace(game..card);     //trace(game..card.*);     //trace(game.title);     //trace(game.title.nodeKind());     trace(C1);     trace(C2);         C1 = Math.floor(Math.random()*(1+8-2))+2;     C2 = Math.floor(Math.random()*(1+8-2))+2;     CName1 = C1 - 2;     CName2 = C2 - 2;         Characters1.gotoAndStop(C1);     Characters2.gotoAndStop(C2);     CharactersName1.text = String(game.cards.card.name[CName1]);     CharactersName2.text = String(game.cards.card.name[CName2]);     attack1.text = String(game.cards.card.attack[CName1]);     attack2.text = String(game.cards.card.attack[CName2]);     damages1.text = String(game.cards.card.damages[CName1]);     damages2.text = String(game.cards.card.damages[CName2]); } function generatecharacterbox() {     Characters1 = new Pokemonbox();     Characters1.x = 140;     Characters1.y = 150;     stage.addChild(Characters1);     Characters2 = new Pokemonbox();     Characters2.x = 410;     Characters2.y = 150;     stage.addChild(Characters2); } myButton.addEventListener(MouseEvent.MOUSE_UP,checkValue); function checkValue(event:MouseEvent):void {         numGoes--;         var playerScore = int(playerScoreScreen.text);     var computerScore = int(computerScoreScreen.text);     if (game.cards.card.damages[CName1] == game.cards.card.damages[CName2])     {         winner.text = "Draw";         trace("Draw");     }     else if (game.cards.card.damages[CName1] > game.cards.card.damages[CName2])     {         playerScore++;         winner.text = "Player Wins";                 trace("Player Wins");     }     else     {         computerScore++;         winner.text = "Computer Wins";                 trace("Computer Wins");     }     trace(computerScore);     trace(playerScore);         playerScoreScreen.text = playerScore.toString();     computerScoreScreen.text = computerScore.toString();     goesLeft.text = numGoes.toString(); } GenerateCards.addEventListener(MouseEvent.CLICK,generation); function generation(event:MouseEvent) {     readByName(); } stop();

Frame 3 Coding:

ActionScript Code:
ActionScript Code: stage.removeChild(Characters1); stage.removeChild(Characters2); playerFinalScore.text = playerScoreScreen.toString(); computerFinalScore.text = computerScoreScreen.toString();

Thanks in advance to any responds.
AnimatedCircle is offline   Reply With Quote
Old 04-07-2012, 07:21 PM   #4
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,183
Default

Make variables for the texts (outside of the functions) in the frame two and save your values to them (in or outside of the functions)

Frame 2 Coding:
ActionScript Code:
var text1:String = "text1 from frame 2"; var text2:String = "text2 from frame 2";

and put them in the textfields on frame three

Frame 3 Coding:
ActionScript Code:
tf1.text = text1; tf2.text = text2; // in the text field object "tf1" should read now: text1 from frame 2 // and in the text field object "tf2" should read now: text2 from frame 2
-:)lauri is offline   Reply With Quote
Old 04-07-2012, 07:27 PM   #5
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Default

Thanks for posting..

what if the values ii want to get out of the text box arent static values..

Its a top trumps game so the value of score could change depending upon what the score each player gets.

if you get me?

Cos on game the player scores 4 and the computer scores 6 or whatever ii want to be able to add it in rather than just state the value is this no matter what the outcome..
AnimatedCircle is offline   Reply With Quote
Old 04-07-2012, 09:27 PM   #6
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Exclamation Text Box.. Please Help.

Hi.. Please Help

ii have two values in frame two that ii want to display in frame 3 how do ii do this ii have already written some code but unsure if it is correct...

well it doesn't work as the values don't actually show up.

Frame 2 Coding:

ActionScript Code:
var game:XML; var Characters1:MovieClip; var Characters2:MovieClip; var C1 = Math.floor(Math.random()*(1+8-2))+2; var C2 = Math.floor(Math.random()*(1+8-2))+2; var CName1 = C1 - 2; var CName2 = C2 - 2; generatecharacterbox(); var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); loader.load(new URLRequest("game.xml")); var numGoes:Number = 10; addEventListener(Event.ENTER_FRAME, numCount); function numCount(event:Event) {         if(numGoes == 0)     {         gotoAndStop(3);     } } function onComplete(evt:Event):void {     try     {         game = new XML(evt.target.data);         readByName();         loader.removeEventListener(Event.COMPLETE, onComplete);         loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);     }     catch (err:Error)     {         trace("Could not parse loaded content as XML:\n" + err.message);     } } function onIOError(evt:IOErrorEvent):void {     trace("an error ocured when attempting to load the XML.\n" + evt.text); } function readByName() {     //trace(game.cards);     //trace(game.cards.card.name);     //trace(game.cards.card.name[0]);     //trace(game..name);     //trace(game..card);     //trace(game..card.*);     //trace(game.title);     //trace(game.title.nodeKind());     trace(C1);     trace(C2);         C1 = Math.floor(Math.random()*(1+8-2))+2;     C2 = Math.floor(Math.random()*(1+8-2))+2;     CName1 = C1 - 2;     CName2 = C2 - 2;         Characters1.gotoAndStop(C1);     Characters2.gotoAndStop(C2);     CharactersName1.text = String(game.cards.card.name[CName1]);     CharactersName2.text = String(game.cards.card.name[CName2]);     attack1.text = String(game.cards.card.attack[CName1]);     attack2.text = String(game.cards.card.attack[CName2]);     damages1.text = String(game.cards.card.damages[CName1]);     damages2.text = String(game.cards.card.damages[CName2]); } function generatecharacterbox() {     Characters1 = new Pokemonbox();     Characters1.x = 140;     Characters1.y = 150;     stage.addChild(Characters1);     Characters2 = new Pokemonbox();     Characters2.x = 410;     Characters2.y = 150;     stage.addChild(Characters2); } myButton.addEventListener(MouseEvent.MOUSE_UP,checkValue); function checkValue(event:MouseEvent):void {         numGoes--;         var playerScore = int(playerScoreScreen.text);     var computerScore = int(computerScoreScreen.text);     if (game.cards.card.damages[CName1] == game.cards.card.damages[CName2])     {         winner.text = "Draw";         trace("Draw");     }     else if (game.cards.card.damages[CName1] > game.cards.card.damages[CName2])     {         playerScore++;         winner.text = "Player Wins";                 trace("Player Wins");     }     else     {         computerScore++;         winner.text = "Computer Wins";                 trace("Computer Wins");     }     trace(computerScore);     trace(playerScore);         playerScoreScreen.text = playerScore.toString();     computerScoreScreen.text = computerScore.toString();     goesLeft.text = numGoes.toString(); } GenerateCards.addEventListener(MouseEvent.CLICK,generation); function generation(event:MouseEvent) {     readByName(); } stop();

Frame 3 Coding:

ActionScript Code:
stage.removeChild(Characters1); stage.removeChild(Characters2); var playerScoreScreen = playerFinalScore; var computerScoreScreen = computerFinalScore; playerFinalScore.text = playerScoreScreen.toString(); computerFinalScore.text = computerScoreScreen.toString();

When it runs it just comes up with [object... in the space which ii dont know why.

Thanks in advance to any responds.

Last edited by AnimatedCircle; 04-07-2012 at 10:06 PM.
AnimatedCircle is offline   Reply With Quote
Old 04-08-2012, 01:13 AM   #7
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,183
Default

You may put single enterframe function to the frame 2 which updates the text fields that are on the stage
  1. In this pseudocode we have text fields "textfield1" and "textfield2" in the frame 2 and text fields "textfield3" and "textfield4" in the frame 3.
    *
  2. We also have to strings "text1" and "text2" that are defined in the frame 2.
    *
  3. Enterframe function "updateTextFields" in the frame 2 checks in which frame user is and if user is in frame 2 it puts value of the "textfield1" to string "text1" and the value of the "textfield2" to string "text2".
    *
  4. If user is in frame 3 the content of the "text1" and "text2" will be changed and the enterframe function "updateTextFields" in the frame 2 will put those values to the text fields "textfield3" and "textfield4" in the frame 3

frame 2
ActionScript Code:
var text1:String; var text2:String; addEventListener(Event.ENTER_FRAME, updateTextFields); function updateTextFields(e:Event):void {     if ( currentFrame == 2 )     {         text1 = textfield1.text;         text2 = textfield2.text;     }     else if ( currentFrame == 3 )     {         textfield3.text = text1;         textfield4.text = text2;     } }

frame 3
ActionScript Code:
text1 += 1; text2 += 2;

Last edited by -:)lauri; 04-08-2012 at 08:45 AM.
-:)lauri is offline   Reply With Quote
Old 04-10-2012, 06:13 PM   #8
AnimatedCircle
Registered User
 
Join Date: Apr 2012
Location: Manchester
Posts: 21
Default

Thanks
AnimatedCircle is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:50 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.