This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-04-06 15:59:26

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Question about a weird syntax error...

Code:

class EnemyShip extends MovieClip
{
    var speed;
    var shootTimer;
    
    function onLoad()
    {
        _x = 700
        _y = Math.random()*250 + 50;
        speed = Math.random()*5 + 5;
        shootTimer = 0;
    }
    
    function onEnterFrame()
    {
        _x -= speed;
        if(_x < -100)
        {
                this.removeMovieClip();
        }
        if(this.hitTest(_root.ship))
        { 
            explode();
        }
        
        shootTimer +=1;
        if(shootTimer > 30)
        {
            shootTimer = 0
            var missile = _root.attachMovie("EnemyMissile","EnemyMissile" + _root.getNextHighestDepth(). _root.getNextHighestDepth());
            missile._x = _x -50
            missile._y = _y + 2
        }
    }
    
    function explode()
    {
        var explosion = _root.attachMovie("Explosion","Explosion" + _root.getNextHighestDepth()._root.getNextHighestDepth());
        explosion._x = _x;
        explosion._y = _y;
        this.removeMovieClip();
    }

I get a syntax error saying "There is no method with the name '_root'.

Last edited by juststickman (2010-04-06 16:00:39)


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#2 2010-04-06 16:00:57

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Question about a weird syntax error...

Also the ship keeps ending up in the top left corner.... Does this have something to do with

Code:

var missile = _root.attachMovie("EnemyMissile","EnemyMissile" + _root.getNextHighestDepth(). _root.getNextHighestDepth());
            missile._x = _x -50
            missile._y = _y + 2

?

Sorry about double post, the forum wouldn't let me post both parts in one post.

Last edited by juststickman (2010-04-06 16:01:18)


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#3 2010-04-06 16:06:50

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Question about a weird syntax error...

I don't know how whatever programming language you're using works  hmm  (I'm guessing actionscript because of the term "movies", and you've been talking about it)

You could temporarily remove the one part and see if that fixes it.

Offline

 

#4 2010-04-06 16:10:00

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Question about a weird syntax error...

BWOG wrote:

I don't know how whatever programming language you're using works  hmm  (I'm guessing actionscript because of the term "movies", and you've been talking about it)

You could temporarily remove the one part and see if that fixes it.

I know that the error is those parts because the syntax error says it's on those lines...

Yeah, it's actionscript.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#5 2010-04-07 05:06:29

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Question about a weird syntax error...

Is anybody there?

I need a better place to post these problems...


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#6 2010-04-07 12:32:31

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Question about a weird syntax error...

Don't post AS code here, most people here won't even recognize the syntax.

Use the newgrounds flash forum //best for fast replies
the kirupa forums
or the flashkit forums

As for your problem, try getting rid of the var "name" = _root.blah...
You only need the _root.blah... part

Also remember to set the linkage if you use the attachmovie command.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer