Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
OOP ActionScript

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Knjige
View previous topic :: View next topic  
Author Message
cicibaka



Joined: 28 Aug 2004
Posts: 7

PostPosted: 31.10.2004 00:24    Post subject: OOP ActionScript Add user to your forum ignore list Reply with quote

Ajde pliz recite di ima za skinut nesto na temu Objektno programiranje u ActionScriptu?
Back to top
View user's profile Send private message
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 31.10.2004 18:38    Post subject: Add user to your forum ignore list Reply with quote

na žalost, nikad nisam tražio nigdje drugdje nego na macromedia:
http://macromedia.com/devnet/mx/flash/actionscript.html

no, tamo ima dovoljno primjera i tutoriala da naučiš sve finte... ja više ne napišem niti jedan flash filmić bez bar 3-4+ class fajla Wink

OOP rulz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cicibaka



Joined: 28 Aug 2004
Posts: 7

PostPosted: 01.11.2004 10:53    Post subject: Add user to your forum ignore list Reply with quote

Hvala! Ma znam da ima hrpa materijala al je jednostavnije skinut cijelu knjigu od jednom i lakše mi je učit od početka jer sam relativno nov u AS-u općenito.
Back to top
View user's profile Send private message
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 02.11.2004 00:01    Post subject: Add user to your forum ignore list Reply with quote

cicibaka wrote:
...jer sam relativno nov u AS-u općenito.

Onda si daj par dana da naučiš AS osnove: variable scope, movieclip object, event listeners... nakon toga počni OOP

Prije toga svakako nauči movieclip object i sve metode jer će ti OOP biti najkorisnije za ekstenzije MovieClip objecta:
Code:
dynamic class MyClip extends MovieClip {
  // some code here
}

Sad ću se malo praviti važan, ali ovo je moja prva klasa (koja je svojevremeno definirala kuglice koje skaču po ekranu):
Code:
dynamic class Ball extends MovieClip {
   var Velocity:Vector;
   var nextVelocity:Vector;
   var R:Number;
   var Paths:Array;
   var path:MovieClip;
   var numPathClips:Number;
   var pathClipIndex:Number;
   var speedVector:MovieClip;
   function Ball(){
      Paths = new Array();
      numPathClips = 150;
      var z:Number = _root.pauser.getDepth();
      Velocity = new Vector(0,3);
      nextVelocity = null;
      R = _width/2;
      //create ball PATH movie clips
      while(_root.getInstanceAtDepth(z)){
         trace("Instance at depth "+z+": "+_root.getInstanceAtDepth(z));
         z++;
      }
      for(pathClipIndex=0; pathClipIndex<numPathClips; pathClipIndex++,z++){
         Paths[pathClipIndex] = _root.createEmptyMovieClip(_name+"_path"+pathClipIndex,z);
         //trace(Paths[pathClipIndex]._name+" created on depth "+z);
      }
      pathClipIndex = 0;
   }
   function bounceX(){
      if(!nextVelocity){
         nextVelocity = new Vector(-Velocity.x,Velocity.y);
      } else {
         nextVelocity.x = -Velocity.x;
      }
   }
   function bounceY(){
      if(!nextVelocity){
         nextVelocity = new Vector(Velocity.x,-Velocity.y);
      } else {
         nextVelocity.y = -Velocity.y;
      }
   }
   function flyBabyFly(){
      _x += Velocity.x;
      _y += Velocity.y;
   }
   function onEnterFrame(){
      if(_root.started){
         if(Velocity.module()<0.4){
            _root.startbutton.onRelease(); //stops the animation if too slow
            continue;
         }
         if(_root.pathVisToggle.selected){
            var i:Number;
            for(i=0;i<numPathClips;i++){
               if(i==pathClipIndex){
                  with(Paths[i]){
                     _alpha = 100;
                     _visible = true;
                     clear();
                     lineStyle(0,0xFF0000,40);
                     moveTo(this._x,this._y);
                  }
               } else {
                  Paths[i]._alpha -= 100/numPathClips;
               }
            }
         }
         Velocity.addV(_root.Gravity);
         //checks for obstacles:
         _root.checkObstacles(this);
         //now that it has moved, draw the path:
         if(_root.pathVisToggle.selected){
            Paths[pathClipIndex].lineTo(_x,_y);
            pathClipIndex = (pathClipIndex+1)%numPathClips;
         }
         //update the speed vector:
         syncSpeedVector();
      }
   }
   function syncSpeedVector(){
      speedVector._x = _x; speedVector._y = _y;
      speedVector._rotation = Velocity.angle();
      speedVector._width = Velocity.module()/1.5 + 5;
   }
   function onPress(){
      if(!_root.started){
         destroyPath();
         speedVector._visible = false;
         startDrag(this);
      }
   }
   function onRelease(){
      if(!_root.started){
         stopDrag();
         Velocity = new Vector(3,0);
         nextVelocity = null;
         syncSpeedVector();
         speedVector._visible = _root.speedVisToggle.selected;
      }
   }
   function destroyPath(){
      var i:Number;
      for(i=0;i<numPathClips;i++){
         Paths[i]._visible = false;
      }
   }
}


...radio sam to dosta dugo Smile

Sve se to kasnije može puno elegantnije i ljepše, kad stekneš malo prakse.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cicibaka



Joined: 28 Aug 2004
Posts: 7

PostPosted: 03.11.2004 13:57    Post subject: Add user to your forum ignore list Reply with quote

Da, upravo radim na tome. LeaveMeBe Shocked Very Happy
Back to top
View user's profile Send private message
Adrian



Joined: 02 Apr 2004
Posts: 692
Location: Around & about

PostPosted: 09.11.2004 20:28    Post subject: Add user to your forum ignore list Reply with quote

@sulien Shocked Shocked Shocked Shocked

a ja misla....... uf. jedva sam odskrolao. svaka čast, hm, na strpljenju.

_________________
The quest for certainty blocks the search for meaning. Uncertainty is the very condition to impel a man to unfold his powers.
http://origami.hr
Back to top
View user's profile Send private message Visit poster's website
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 09.11.2004 21:32    Post subject: Add user to your forum ignore list Reply with quote

To je samo strpljenje, cijeli class su samo osnovne stvari kad pogledaš...

Stavio sam to kao primjer kako ekstenzijama na postojeće klase (MovieClip ovdje) možeš jednostavno definirati metode i properties objekata za koje ti to treba... počneš tako, a završiš (kad imaš malo iskustva) na pisanju velikih općenitih klasa koje će ti služiti bilo gdje -- jedna od takvih je "Vektor" klasa koju sam napisao da mogu napraviti tip podataka vektor koje mogu zbrajati, množiti skalarom, projecirati na drugi... Staviš file u neki class shared folder i koristiš u bilo kojem projektu gdje ti treba

EDIT: naravno, vjerojatno sam time izmišljao toplu vodu, no dobro Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Knjige All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group