A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Looping Sprite Help! Please, i'm at the last part of my project!

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    37

    Looping Sprite Help! Please, i'm at the last part of my project!

    Hi, Thank you in advance for any help rendered.


    What i'm trying to accomplish is to:

    1. load all bitmaps such as sfFish1, sfFish2, sfFish3, newborn when they meet the conditions( the ifs conditions) before I start moving them to the right by 30 from a random x value.

    2. When the bitmap hit the last x value 1366, it re-enters from the left edge and starts moving and loops itself.

    PLEASE HELP! this is the last part of the project!
    Code:
    var s2:SharedObject = SharedObject.getLocal("studentlist");
    var slist:Array = s2.data.name;
    
    
    for (var i:String in slist) { 
        var sname:SharedObject = SharedObject.getLocal(slist[i]);
    	var subjchosen = sname.data.subjectchosen;
    	var spetname = sname.data.petname;
    	var spetspecies = sname.data.petspecies;
    	var snBubbles:int = sname.data.bubblesscore;
    
    if (snBubbles <= 5) {
    	 var sfish1:BitmapData = new newborn(5,5);
      	 var sfFish1:Bitmap = new Bitmap(sfish1);
    	 var s:Sprite=new Sprite();
    		s.addChild(sfFish1);
    		addChild(s);
     		 s.x= 670;
      		 s.y= 180;
    		 
    		function fadeCircle(event:Event):void
    {
        s.x += 30;
        
        if (s.x == 1366)
        { 
    	    s.x = 0;
             //Don't KNOW WHAT TO CODE HERE!!!//
        }
    }
    
        s.addEventListener(Event.ENTER_FRAME, fadeCircle);
    
    }
    }
    
    
    
    if (snBubbles > 5 && snBubbles <= 20) {
    	 var s5to20:String = spetspecies+"5";
    	 var ss5to20:Class = getDefinitionByName(s5to20) as Class;
    	 var sfish2:BitmapData = new ss5to20(0,0);
      	 var sfFish2:Bitmap = new Bitmap(sfish2);
      addChild(sfFish2);
      sfFish2.x= 670;
      sfFish2.y= 180;
      currentlyShowing2 = sfFish2;
    }
    
    if (snBubbles >20 && snBubbles <= 40) {
    	 var s20to40:String = spetspecies+"20";
    	 var ss20to40:Class = getDefinitionByName(s20to40) as Class;
    	 var sfish3:BitmapData = new ss20to40(0,0);
      	 var sfFish3:Bitmap = new Bitmap(sfish3);
      var t:Sprite=new Sprite();
    		t.addChild(sfFish3);
    		addChild(s);
     		 t.x= 670;
      		 t.y= 180;
    		 
    		function fadeCircle2(event:Event):void
    {
        t.x += 30;
        
        if (t.x > 1366)
        {
            t.removeEventListener(Event.ENTER_FRAME, fadeCircle2);
        }
    }
    
        t.addEventListener(Event.ENTER_FRAME, fadeCircle2);
    }
    
    if (snBubbles > 40) {
    	var ss40:String = spetspecies;
    	 var s40:Class = getDefinitionByName(ss40) as Class;
    	 var sfish4:BitmapData = new s40(0,0);
      	 var sfFish4:Bitmap = new Bitmap(sfish4);
       		var u:Sprite=new Sprite();
    		u.addChild(sfFish4);
    		addChild(s);
     		 u.x= 670;
      		 u.y= 180;
    		 
    		function fadeCircle3(event:Event):void
    {
        u.x += 30;
        
        if (u.x > 1366)
        {
            u.removeEventListener(Event.ENTER_FRAME, fadeCircle3);
        }

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    if (s.x >= 1366)
    {
    s.x = Math.random() * 200;// for example, it will start anywhere from 0 to 200
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    37
    actually, i was thinking about how to loop the sprite after loading all the instances on stage... i'm so stucked!

  4. #4
    Member
    Join Date
    Jul 2009
    Posts
    37
    package beautyfulminds.com.own{
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.utils.getDefinitionByName;


    public class ISprite extends Sprite {

    public var sPspecies:String;
    public var sBubbled:uint;
    public var sPsprite:Sprite = new Sprite();

    public function ISprite(param_sPspecies:String, param_sBubbled:uint) {

    sPspecies = param_sPspecies;
    sBubbled = param_sBubbled;
    trace(sPspecies);
    }


    public function createISprite():void {
    var SP:Class = getDefinitionByName(sPspecies) as Class;
    trace(sPspecies);
    var sPBB:BitmapData = new SP(20,20);
    var sPBP:Bitmap = new Bitmap(sPBB);


    sPsprite.addChild(sPBP);
    sPsprite.x =120;
    sPsprite.y = 400;
    sPsprite.addEventListener(Event.ENTER_FRAME, animateISprite); <----- should there be a listener for the parent of this or is this line fine?
    }




    private function animateISprite(e:Event):void {

    sPsprite.x +=20;

    if (sPsprite.x >= 1336) {
    sPsprite.x =0;
    }
    }
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center