开发者

Return AS3.0 Int value

开发者 https://www.devze.com 2023-02-08 12:21 出处:网络
I am trying to return an int value from actionscript inside a symbol. This is the code inside of the symbol/movieclip.

I am trying to return an int value from actionscript inside a symbol.

This is the code inside of the symbol/movieclip.

function flytt():void{
   var flyttInMb:int=Math.random() * 8;
   if(flyttInMb==0){
      x=243,30;
      y=171,65;
   }
}

This is the code I have tried for returning the flyttInMb to the actionscript that is the game, instead of inside one of the symbols, and what I get is this: Return value must be undefined. Any way I can return the flyttInMb out of the symbol, onto my actionscript?

This is how I try to call the flyttInK and the flyttInMb:

if(flyttInK==flyttInMb){
   Kone.flytt();
   Baby.flytt();
}

The thing is.. I want to keep the flyttInMb value, so that I can move the Kone and the baby if开发者_StackOverflow社区 their number is the same, so no mole ever appears on the same spot.


try this to get a return value from a method:

function returnValue():uint
{
  return Math.round(Math.random()*8);
};

Rob


Sorry for adding a new answer, but I feel like it is better this way.

In order to be able to return anything from a method you have to actually set it in the method declaration and you have to return a value in the method. See below:

In the movie clip symbols

function flytt():uint
{
   var flyttInMb:uint = Math.round(Math.random() * 8);

   if(flyttInMb == 0)
   {
      x=243.30; //Use full stop instead if comma!
      y=171.65; //Use full stop instead if comma!
   }

   return flyttInMb;
};

In the method declaration I say I will return a uint value and the last line of the method returns the generated random number.

In your main script

To be honest I don't understand what you are trying to do with this:

if(flyttInK==flyttInMb){
   Kone.flytt();
   Baby.flytt();
}
  • what is flyttInk?
  • what is flyttInMb - it has got the same name as the generated value in the symbol script.
  • The Kone.flytt(); and Baby.flytt(); calls seem to be static class method calls which won't return anything in this context. Try to call the actual instantiated items' methods which would be something like this:

var kone:Kone = new Kone(); ... var returnValueOfKoneInstance:uint = kone.flytt();

I hope you get closer with this,

Rob

0

精彩评论

暂无评论...
验证码 换一张
取 消