Jump to content


Function calling.


  • You cannot reply to this topic
9 replies to this topic

#1 Wazzup

    Young Padawan

  • Members
  • Pip
  • 217 posts

Posted 16 October 2006 - 03:59 PM

hello,

im trying to create a slot machine, im now in the stage were i want to try and put random icons on sliders on a push of the button, when i got that down i can get on to the other stuff in want to put in it. Problem is it doesn't do anything.

Quote

//variables
var muntje
var button

//functions
//Initialize
function Initialize(){
tellTarget ("/left_slide") {
gotoAndStop(1);
}
tellTarget ("/middle_slide") {
gotoAndStop(2);
}
tellTarget ("/right_slide") {
gotoAndStop(3);
}
}
//randomize
function Randomize(){
LeftChip = random(3);
tellTarget ("_root.left_slide") {
gotoAndStop(Number(LeftChip)+1);
}
CenterChip = random(3);
tellTarget ("_root.middle_slide") {
gotoAndStop(Number(CenterChip)+1);
}
RightChip = random(3);
tellTarget ("_root.right_slide") {
gotoAndStop(Number(RightChip)+1);
}
}

//calling functions
// Initialize
onEnterFrame(_root.Initialize());

Under a button i have put the script:

Quote

on(release) {
call("Randomize()");
}

it doesn't do anything however. It does initializes the sliders, they are put on frame 1 2 and 3 of their wanted fruits. I have used part of the code from another slot machine macromedia made, but they used frames to get to random fruits. I want to do it with function.

#2 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 16 October 2006 - 04:08 PM

actually you don't need to call your functions with call("yourfuntion");
you can just use the functions name:

...
Randomize();
...

that code was made for flash 4 or 5 which didn't had that many functions like mx or 8, review the code and change it to AS 2.0

#3 Wazzup

    Young Padawan

  • Members
  • Pip
  • 217 posts

Posted 16 October 2006 - 04:22 PM

ehm i tried what u say, but that doesn't work either. It does execute the initialize function, but doesnt execute the randomize function when i press the button.

I have added the file, can anyone check it, and tell me what i did wrong?

http://www.yourfilehost.com/media.php?cat=...t_machinev2.fla

#4 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 16 October 2006 - 04:33 PM

Change your telltargets to the normal way. For instance,
_root.right_slide.gotoAndStop(Number(RightChip)+1);

Theres probably nothing wrong with them, but you never know..

#5 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 16 October 2006 - 04:45 PM

your randomize function starts up, the only problem you have is that this line.
_root.right_slide.gotoAndStop(Number(RightChip)+1);
doesn't output a number, if you do a trace, you will see that it replies with a NaN which means: Not a Number

#6 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 16 October 2006 - 04:50 PM

bump for the answer :(

here the new randomize function:

//randomize
function Randomize() {
	var LeftChip:Number = random(3);
	tellTarget ("_root.left_slide") {
		_root.left_slide.gotoAndStop(LeftChip+1);
	}
	var CenterChip:Number = random(3);
	tellTarget ("_root.middle_slide") {
		_root.middle_slide.gotoAndStop(CenterChip+1);
	}
	var RightChip:Number = random(3);
	tellTarget ("_root.right_slide") {
		_root.right_slide.gotoAndStop(RightChip+1);
	}
}

the problem was clearly that the variables were a string, you can't add a number to a string. :D

have a try now :)

Edited by funkysoul, 16 October 2006 - 04:50 PM.


#7 Wazzup

    Young Padawan

  • Members
  • Pip
  • 217 posts

Posted 16 October 2006 - 04:57 PM

^tnx, that worked! Don't really get it anyway, in the tutorial i found they did it that way, and that worked fine so.

#8 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 16 October 2006 - 05:06 PM

The problem is as mentioned that all those variables were stated as a String.
You can't make mathematical functions with Strings, so you need to strictly type the variables as they are supposed to be used.

that might have worked for older flash versions but not on the new ones, most of the code you have there has been deprecated, and latest with AS3 your code will not work anymore.

Example, to summarize
	var RightChip:Number = random(3);
	tellTarget ("_root.right_slide") {
		_root.right_slide.gotoAndStop(RightChip+1);
Outputs: a random number and adds 1

RightChip = random(3);
tellTarget ("_root.right_slide") {
_root.right_slide.gotoAndStop(Number(RightChip)+1);
Outputs: NaN = Not a Number

Edited by funkysoul, 16 October 2006 - 05:06 PM.


#9 Wazzup

    Young Padawan

  • Members
  • Pip
  • 217 posts

Posted 16 October 2006 - 05:38 PM

eh this is getting weird. I have it working like this: (dont watch the counter)

//randomize
function Randomize1(){
LeftFruit = random(3);
tellTarget(_root.left_slide.gotoAndStop(Number(LeftFruit)+1));
slidercounter++;
}

function Randomize2(){
CenterFruit = random(3);
tellTarget(_root.middle_slide.gotoAndStop(Number(CenterFruit)+1));
slidercounter++;
}

function Randomize3(){
RightFruit = random(3);
tellTarget(_root.right_slide.gotoAndStop(Number(RightFruit)+1));
slidercounter++;
}

when i try it your way it doesnt work anymore :-S

But i need the number anyhow, cause later i have to compare the 3 of there equal theres a winner movieclip.

http://www.yourfilehost.com/media.php?cat=...t_machinev2.fla

here's the .fla, thought you might want to figure this out aswell since your the one here with more knowledge, and probably understands it. Dont mind the counter doesnt work yet. Im still figuring that out. I want to have 1 slide at a time stop. So you have to press the button 3 times in order to stop all slides. Maybe you can help me with that 2?

grtz, Snuurtje

Edited by Wazzup, 16 October 2006 - 05:43 PM.


#10 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 16 October 2006 - 05:42 PM

ok that might work but again:
- You use old scripting
- You use 3 functions instead of one





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users