  | |  Re: [flashpro] variable increases by more than 1 + random negative
number | Re: [flashpro] variable increases by more than 1 + random negative
number
2004-06-18 - By Jonathan E
Back 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 = [];
> > > >for(i=0; i <this.maxAllies; i++){
> > > > ally = attachMovie( "ally_mc ", "a "+i, i);
> > > > alliesArray[i] = ally;
> > > > ally._x = Math.random()*750;
> > > > ally._y = Math.random()*470;
> > > >}
> > > >
> > > >and then FRAME 3:
> > > >myListener = new Object();
> > > >myListener.onKeyUp = function() {
> > > > if (Key.getCode()== "90 ") {
> > > > l = maxAllies + 1;
> > > > maxAllies++;
> > > > ally = attachMovie ( "al_mc ", "a "+l, l);
> > > > alliesArray.push(ally);
> > > > ally._x = _xmouse;
> > > > ally._y = _ymouse;
> > > > }
> > > >};
> > > >Key.addListener(myListener);
> > > >
> > > >
> > > > >From frame 3, the user could re-start the movie
> > > >
> > > >
> > >and go
> > >
> > >
> > > >back to frame 1, or to frame 2. I am not too
> > > >
> > > >
> > >familiar
> > >
> > >
> > > >with creating objects and listeners, so I dont
> know
> > > >where the best place is to delete the listener
> and
> > > >
> > > >
> > >how
> > >
> > >
> > > >this should be done. Are these right:
> > > >
> > > >Key.removeListener(myListener);
> > > >delete myListener;
> > > >
> > > >And actually, which one of these should be used?
> or
> > > >should both of them be used? I tried putting
> these
> > > >codes a bit everywhere (because I have a few
> > > >
> > > >
> > >similar
> > >
> > >
> > > >movies which the user can load), so I dont know
> > > >
> > > >
> > >where
> > >
> > >
> > > >they are really effective. Could placing them on
>
=== message truncated ===
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
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/
|
|
 |