  | |  | random negativenumber | random negativenumber
2004-06-19 - By Jonathan E
Back Hi Joe!
Thanks for the code. Took me some time to learn about
the strict typing thing, but managed to translate it
for Flash MX. Also learned about the "?: " conditional!
Cheeers :)
jonathan.
--- Joe Martinez
<joseph.martinez@(protected) > wrote:
> Here ya go...
> -- if the function is a class member you may want to
> set it private or
> whatever.
> -- If you are exporting for old version of flash
> remove the strict variable
> typing.
> -- if you wan 't to change the percent of time it
> generates 1 or -1 chg the
> ..49 to something else. Right now it will gen. 50% 1
> and 50% -1.
>
> function randNum():Number{
> var myNum:Number = Math.random();
> return myNum > .49 ? 1 : -1;
> }
>
> Hope this helps
> Joe
>
> -- --Original Message-- --
> From: flashpro-bounces@(protected)
> [mailto:flashpro-bounces@(protected)] On
> Behalf Of Jonathan E
> Sent: Friday, June 18, 2004 4:11 PM
> To: Mailing list for professional Flash designers
> and developers
> Subject: Re: [flashpro] variable increases by more
> than 1 + random
> negativenumber
>
> Hi Rick
>
> Thanks for the link! I definitely need a good
> understanding of OOP and that link will certainly
> help.
>
> anyway, other than that, I need a function which
> will
> randomly return either -1 or 1 (but not zero). I 've
> been thinking about that the whole night but cant
> seem
> to be able to do it :(
>
> Can anyone help me about that?
>
> Cheeers!
>
> jonathan.
>
>
>
> --- Rick Terrill <rick-flashpro@(protected) > wrote:
> > Hi Jonathan,
> >
> > I 'm glad you 've got it working.
> >
> > If that all sounded foreign, then I 'm betting
> you 're
> > not familiar with
> > Object-Oriented programming. I could post some
> > code, but without
> > understanding how and why it works, then it 's no
> > better than your
> > current solution :)
> >
> > I did a quick google search on OO in Actionscript
> > and found a decent
> > article that describes what OO is (with a slant
> > towards actionscript):
> >
> http://www.peachpit.com/articles/article.asp?p=31465
> >
> > From there you should be able to start creating
> > classes and objects and
> > moving your code off the main timeline (a goooood
> > thing)!
> >
> > There are distinct differences in the OO
> > capabilities between MX and
> > MX2004. Although technically you can accomplish
> the
> > same result in
> > either, ActionScript2.0 (in MX2004) provides
> > language constructs,
> > syntax, and organization which bring ActionScript
> > much more in line with
> > the fundamental OO philosophies.
> > Either way, as you read up on OO in AS, make sure
> > that what you 're
> > reading is targeted at your version of Flash!
> >
> > (i hope i 'm not too verbose :)
> >
> > Rick
> >
> > Jonathan E wrote:
> >
> > >Hey Rick
> > >
> > >Thanks for your reply. The last part of your
> email
> > >sounded totally alien to me however! :) Is that
> > >relatively easy to learn nand do (I mean creating
> a
> > >class for handling the event etc)? If it is, yeah
> > >could you please give me a bit more details and a
> > >quick example? If it 's too complicated, that 's
> ok.
> > >dont bother about it, because removing the
> > listener
> > >by putting removeListener in the frames where
> > needed
> > >seems to work fine.
> > >
> > >Thanks again!
> > >
> > >jonathan.
> > >
> > >
> > >--- Rick Terrill <rick-flashpro@(protected) >
> > wrote:
> > >
> > >
> > > >Definitely don 't put the removeListener and
> delete
> > > >statements in the
> > > >same frame as the object creation and listener
> > > >reassignment. Statements
> > > >within a single frame do not necessarily execute
> > in
> > > >order.
> > > >
> > > >The preferable method would be to put all the
> > > >actions of frames 1-3 in a
> > > >..as file and include it in frame 1.
> > > >Alternatively, you could create a class for
> > handling
> > > >this event and
> > > >create an object from it in _global on frame1.
> > > >
> > > >If this isn 't clear, then I can be more specific
> > :)
> > > >
> > > >Rick
> > > >
> > > >Jonathan E wrote:
> > > >
> > > >
> > > >
> > > > >Hello. Thanks for the responses
> > > > >
> > > > >Yep the code was indeed being run more than
> once!
> > > > >
> > > > >
> > > >So
> > > >
> > > >
> > > > >it 's this which is causing it then!
> > > > >
> > > > >The code is actually in frame 3. So does this
> > mean
> > > > >that I have to put:
> > > > >
> > > > >Key.removeListener(myListener);
> > > > >delete myListener;
> > > > >
> > > > >at the beginning of frames 1 and 2? (because
> the
> > > > >
> > > > >
> > > >user
> > > >
> > > >
> > > > >can leave frame 3 and go back to frames 1 or
> 2).
> > Or
> > > > >can I just simply put "removeListener " and
> > "delete
> > > > >myListener " right at the beginning of frame 3
> > where
> > > > >the listener is created?
> > > > >
> > > > >To be a bit more clear, the way the movie is
> > built
> > > > >
> > > > >
> > > >is:
> > > >
> > > >
> > > > >Frame 1:
> > > > >In frame 1, the variable maxAllies is set to
> 20.
> > > > >When the user clicks on a button, the movie
> goes
> > to
> > > > >frame 2, where there 's the following:
> > > > >
> > > > >FRAME 2:
> > > > >alliesArray = [];
>
=== message truncated ===
__ ____ ____ ____ ____ ____ ______
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
send message to the list: mailto:flashpro@(protected)
[FlashPro] list info, subscribe, archive: http://flash-list.com/
There 's also a WebPro mailing list: http://webdesign-list.com/
cutting-edge sounds for flash: http://flash-sounds.com/
|
|
 |