A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: timeline loop

  1. #1
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292

    timeline loop

    Hi
    i've got something simple in my main time line.

    I know i must be missing some kind of loop function, as the hold down doesnt work unless i keep clicking. And my trace doesnt work unless it starts on the 'enemy'.
    I'm just not sure what

    Thanks for any help!

    Code:
    import flash.events.MouseEvent;
    
      _left.addEventListener(MouseEvent.MOUSE_DOWN, moveLeft);
      function moveLeft(e:MouseEvent){
    	  _hero.x--;
    	  }
      
        _right.addEventListener(MouseEvent.MOUSE_DOWN, moveRight);
      function moveRight(e:MouseEvent){
    	  _hero.x++;
      }
      
        _up.addEventListener(MouseEvent.MOUSE_DOWN, moveUp);
      function moveUp(e:MouseEvent){
    	  _hero.y--;
      }
      
          _down.addEventListener(MouseEvent.MOUSE_DOWN, moveDown);
      function moveDown(e:MouseEvent){
    	  _hero.y++;
    }
    
    if(_hero.hitTestObject(_enemy)){
       trace("hit");
       }
    Ryan :]

  2. #2
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    Try replacing:

    Actionscript Code:
    if(_hero.hitTestObject(_enemy))
    {
       trace("hit");
    }

    with, and add the Event class.

    Actionscript Code:
    stage.addEventListener(Event.ENTER_FRAME, onEnter);

    function onEnter(e:Event):void
    {
        if(_hero.hitTestObject(_enemy))
       {
           trace("hit");
       }
    }

  3. #3
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292
    Hey! Yeah that worked great thanks, for the text anyway, still havent fixed the movement, but that's not that important yet.

    Is there anychance you could take a look at my class? save me eventually making a new thead.
    'My error is Access of possibly undefined property _hero'

    This code is in my 'enemy' class. my movement text for the 'hero' is on my timeline.
    Thanks!
    Code:
    package  {
    	import flash.display.MovieClip;
    	import flash.text.TextField;
    	
    	public class enemy extends MovieClip{
    
    public var enemy1:enemy = new enemy();
    
    public var enemyTxt:String = new String();
    
    var txtField:TextField = new TextField();
    
    public function enemy (){
       if(this.hitTestObject(_hero)){
       drawText();
       } 
    }
    
    private function drawText(txt:String = "Some Text Here"){
    	//Draw from array goes here
    	trace(txt);
    	}
    }
    }
    Ryan :]

  4. #4
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    You can't access _hero from enemy class because hero is not a variable in the class. If you want to use it, you must somehow pass hero into your enemy class and interact with it. f you want to detect hitTest with an external variable, you probably have to pass _hero into the enemy class. I'm not on a computer with flash right now so I can't be sure if this is going to work but have a try:

    Actionscript Code:
    package
    {
        import flash.display.*;
        import flash.text.*;

        public class Enemy extends MovieClip
        {
            public function Enemy(_hero:Object) //or MovieClip, or the type of your hero
            {
                if(this.hitTestObject(_hero))
                {
                    trace("Hit");
                }
            }
        }
    }

    Also, does your drawText function work just fine? Wouldn't Flash throw up an error saying it's expecting 1 argument?

  5. #5
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292
    Ah damn, thats a shame haha.
    I've been looking for tutorials for classes and objects all day, unable to find a clear one. Still don't understand how they work or connect with each other.

    Thanks but unfortunately that didn't work, got some crazy output
    Code:
    ArgumentError: Error #1063: Argument count mismatch on enemy(). Expected 1, got 0.
    	at flash.display::Sprite/constructChildren()
    	at flash.display::Sprite()
    	at flash.display::MovieClip()
    	at movinghero2_Scene1_fla::MainTimeline()
    Yeah surprisingly that did work (a first!)
    Ryan :]

  6. #6
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    It says it's missing the _hero argument in the enemy's constructor method. Wherever in your timeline code that you have
    PHP Code:
    new enemy (); 
    you have to replace with
    PHP Code:
    new enemy (_hero); 

  7. #7
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292
    hmm, that didn't work either haha!
    I'm sure it would of i'm just implementing it wrong.

    Cheers for the replies, i'm just guna go start at the very basics again!
    Thanks!
    Ryan :]

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