PDA

View Full Version : Component problem


nyghtrunner
01-16-2008, 07:11 PM
Hey all,

So I'm not sure if I'm posting this the right area, as it involves Flex 3 (Beta 2), but at it's core, it involves Flash/AS3 as well.

Here's my problem:

I'm trying to build a component in Flash that will ultimately be taken and used in Flex. It's pretty simple, just a skinned button that has some custom functionality to change the frame based on the instance, and some other stuff in terms of EventListeners...

So I installed the Flex Component kit, converted the library symbol to a Flex Component, and voila, I can add it to the stage using the custom namespace in flex. However, it doesn't have any functionality. Ok, so I go look at the component, and see that it's no longer linked up to my custom class. So I relink it to that class, and Flash tells me "The base class will not be used because the class specified is already defined and extends its own subclass. If you wish to use the base class, please specify a class name in the Class field that will be auto-generated or enter the default base class "flash.display.MovieClip" in the Base Class field."

Ok, so I enter the flash.display.MovieClip in the base class field, and it works... sort of. I no longer have access to the component in the custom namespace, and when I instantiate the class in the flex <mx:script> tag, it traces out that the class has indeed been placed on the stage, at the correct depth, and with the correct coordinates, etc... The problem is that the class doesn't actually have any graphic (ie - component) associated with it...

So I dig around online, and find a few places saying that the class needs to extend "mx.flash.UIMovieClip", instead of the MovieClip class. So I tried that. I import the UIMovieClip class, and attempt to extend it in the .as file, but I get this error:


1017: the definition of base class UIMovieClip was not found.


How can this be? When I typed out the import, the prompters took me right to the UIMovieClip class in the "mx.flash." path. So the prompters find it, but the code can't?!

So I can't extend the UIMovieClip class in code, so that I can extend it in the path of the component, and leaving it extending the base MovieClip class doesn't work either... I am really not sure what is going on, so if anyone has any ideas...

Here's the AS Class.


package AvatarBuilder.ASClasses { //custom path for a Flex RSL in the document. This is where all my custom classes live, and I'm not having a problem with them.
import fl.transitions.Tween; //I also moved these to the RSL, since they do not seem to be native to Flex. Eventually will be replaced with TweenLite or something...
import fl.transitions.easing.*; //See above
import flash.display.MovieClip; //seems to be found and work.
import mx.flash.UIMovieClip; //seems to be found, but gives an error
import flash.events.*;

public class myButton extends UIMovieClip { //if I change this to MC, the import mx.flash.UIMovieClip spits out an error. If I take that out, and use MC, no errors.

//declare the vars that make it go
private var localScalerX:Number;
private var localScalerY:Number;

public function myButton() { }

public function init(xScale:Number,yScale:Number):void {
this.localScalerX = xScale;
this.localScalerY = yScale;
this.addEventListener(MouseEvent.MOUSE_OVER,rollOv erHandler);
this.addEventListener(MouseEvent.MOUSE_OUT,rollOut Handler);
}

private function rollOverHandler(e:Event):void {
trace("hi");
var bigTweenX:Tween = new Tween(this,"scaleX",Strong.easeInOut,this.scaleX,this.localScalerX,.1 ,true);
var bigTweenY:Tween = new Tween(this,"scaleY",Strong.easeInOut,this.scaleY,this.localScalerY,.1 ,true);
}
private function rollOutHandler(e:Event):void {
trace("hi2");
var smallTweenX:Tween = new Tween(this,"scaleX",Strong.easeInOut,this.scaleX,1,.1,true);
var smallTweenY:Tween = new Tween(this,"scaleY",Strong.easeInOut,this.scaleY,1,.1,true);
}

}
}


One more note, and this might be part of the problem... This is the base class for another class that adds custom functions for the buttons. The code for that is here (if it makes a difference...):


package AvatarBuilder.ASClasses {
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.display.MovieClip;
import flash.events.*;
import flash.xml.*;

public class pickButton extends myButton {

//declare the vars that make it go
private var localDirection:String;
private var handlerNum:Number;
private var hostName:*;
private var localNum:Number;
private var scaleRatio:Number;

public function pickButton(myDirection:String,handler:Number,host: *,myX:Number,myY:Number,myNum:Number,myScaleRatio: Number) {
this.localDirection = myDirection;
this.handlerNum = handler;
this.hostName = host;
this.x = myX;
this.y = myY;
this.localNum = myNum;
this.scaleRatio = myScaleRatio;
super.init(scaleRatio,scaleRatio);
this.gotoAndStop(myNum+1);
trace(myNum+1);
trace(this.x);
trace(this.y);
this.addEventListener(MouseEvent.CLICK,clickHandle r);

}

private function clickHandler(e:Event):void {
private function clickHandler(e:Event):void {
trace(this.handlerNum+" was clicked");
var transTweenX:Tween = new Tween(this,"scaleX",Strong.easeInOut,this.scaleX,.85,.1,true);
var transTweenY:Tween = new Tween(this,"scaleY",Strong.easeInOut,this.scaleY,.85,.1,true);
transTweenX.addEventListener(TweenEvent.MOTION_FIN ISH,transBack);

}
private function transBack(e:Event):void {
var transTweenX:Tween = new Tween(this,"scaleX",Bounce.easeInOut,this.scaleX,1,.1,true);
var transTweenY:Tween = new Tween(this,"scaleY",Bounce.easeInOut,this.scaleY,1,.1,true);
}
}
}


When originally tested in Flash, without the Flex, it was working just fine... Anyone have any suggestions? Sorry for being so long winded, but I am really at a loss with this... :confused:

x77686d
03-17-2008, 09:05 PM
I ran into a similar problem just now. I was trying to change the Linkage for a Flex Component from the class LineAnimX to the class LineAnim and got a pop-up with this error:

"The base class will not be used because the class specified is already defined and extends its own subclass. If you wish to use the base class, please specify a class name in the class field that will be auto-generated or enter the default base class 'flash.display.MovieClip' in the Base Class Field".

There was already a LineAnim.as in that directory, so I exited Flash, deleted LineAnim.as (saved the code), and restarted flash. I was then able to change the linked class from LineAnimX to LineAnim without getting that pop-up. It published ok.

I then created LineAnim.as and that worked ok BUT I found that I needed an import for flash.display.MovieClip.

Here's the code:
package
{
import flash.display.MovieClip;
import mx.flash.UIMovieClip;

public class LineAnim extends UIMovieClip {}
}


If I comment out that first import, I get error 1046 at both line 1 and 3: 1046: Type was not found or was not a compile-time constant: MovieClip.

In a seemingly identical component, I don't need that import for MovieClip.

x77686d
03-17-2008, 09:40 PM
I figured out why "import flash.display.MovieClip;" is needed in LineAnim.as: It's because the symbol contains a named MovieClip. If the instance name is removed, the import for MovieClip is not needed!

William Mitchell
Mitchell Software Engineering.com