Jump to content
Search Community

compiled with MXMLC not working ... [SOLVED]

nagipar test
Moderator Tag

Recommended Posts

Hi,

 

I am a newb to AS, Tweening, etc.

 

I wrote an ActionScript (3.0), as follows:

 

package {

 

import flash.text.*;

import flash.events.*;

 

import com.greensock.*;

 

import flash.geom.*;

import flash.media.*;

import flash.filters.*;

import flash.display.*;

import flash.net.*;

 

public class Main extends Sprite {

 

[Embed(source="b.png")]

public var BClass:Class;

 

public function Main():void {

var b:Bitmap = new BClass();

b.x = 400.0;

b.y = 425.0;

addChild(B);

 

var textLocal:TextField = new TextField;

textLocal.appendText("Hello ");

 

textLocal.x = 0;

textLocal.y = 0;

textLocal.width=500;

addChild(textLocal);

 

var i:int = 0;

for ( i=0; i<100; i++) {

TweenMax.to(b, 2, {x:319, y:275});

TweenMax.to(b, 1, {x:442, y:406});

}

}

}

}

 

In the same directory as this .as file, I placed the com directory unzipped from the TweenMax zip.

 

I then run MXMLC (from Flex 3.x SDK) to compile the .as file. It compiles just fine, into a SWF. Problem is, when I run the swf in Flash Player 10, I only see the text (Hello) and the image (b.png image), but the animation does not work. I removed the com directory and the compiler rightly complains about the greensock class not being available. So my thinking is that the compiler is using the class at compile time, but is probably not linking it into the SWF for runtime. But this is only a guess.

 

Any specific insights will be greatly appreciated.

 

Thx.

Link to comment
Share on other sites

Tough to say for sure what's going on with your file, but did you realize that the following code just creates 100 duplicate tweens that overwrite each other?

 

var i:int = 0;
for ( i=0; i    TweenMax.to(b, 2, {x:319, y:275});
   TweenMax.to(b, 1, {x:442, y:406});
}

 

That's a big waste of resources.

 

If you're still running into trouble, please post a simple Flex project archive or FLA file that demonstrates the issue.

Link to comment
Share on other sites

Hi,

 

Thank you for the performance heads-up. right now, I am only trying to learn and get a handle on all of this stuff, starting with AS.

 

I am attaching a flex project. Originally the project was a Flex AS project. Now, i have made it into a regular flex project. The mxml file is just the default - evenutually I will code it as I learn about it.

 

The original problem, which still persists (and is clearly because of something I am doing or not doing) is the following: when I compile the Main.as file (with the greensock com directory in the same location as the Main.as file), using mxmlc, the compile works fine. The generated .SWF file works fine execpt for the animation part - the image shows, but does not animate.

 

I apprecaite any help.

 

Thanks!

Link to comment
Share on other sites

There were several problems, the biggest of which was the fact that you didn't have any of the GreenSock classes - you were using the HTML documentation files instead of the ActionScript files :)

 

I wasn't entirely sure what you were trying to accomplish, but I went ahead and created a basic FLA file that loads your b.png file with a loader and animates it back and forth 100 times at the coordinates you defined (again, not sure if that's the movement you wanted) using TweenMax and a TimelineMax. See the attachment.

 

Hope that helps.

Link to comment
Share on other sites

Hi,

 

Thank you very much for taking the time to look at my archive. When I created the flex project to post here, I inadvertantly included the com directory from the docs directory of Greensock. Originally, in the AS project I used the correct com file (otherwise mxmlc would not have compiled).

 

Your project works fine and I appreciate the effort. Going back to my original AS project, I compared your .as file and mine. Here is the conclusion:

 

If we use your code:

var tl:TimelineMax = new TimelineMax({repeat:100, delay:2});

tl.append(TweenMax.to(b, 1, {x:242, y:206}));

tl.append(TweenMax.to(b, 2, {x:119, y:75}));

things work fine.

 

If i use

 

TweenMax.to(b, 2, {x:242, y:206});

TweenMax.to(b, 2, {x:119, y:75});

 

the two calls seem to be be "optimized" into a single translation. The goals was to have the image start at a point, go along the side of one triangle and come down the other side. TweenMax.to is optimizing them into a motion along the base of the triangle!

 

I am good to go (i am merely learning) thanks to your quick tutorial/education. However, out of curiosity, why are the two call to TweenMax.to being "optimized" - in this case overriding the intent of the animator?

 

Thanks again for your time

Link to comment
Share on other sites

The two calls aren't being "optimized". The 2nd one is overwriting the first one. You cannot have b going to to different places at the same time. You created two tweens that run at the same time going to completely different x/y coordinates. The 2nd one overwrites the first. If you want one to occur before the other one begins, just use the delay property in the 2nd one, or use a TimelineMax like I did in order to sequence them easily.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...