Extend Class Movieclip And Movieclip Off Stage
Hi all, Using Flash 8 and getting over to AS2.0 I got this problem. Could not find any answer on the forum until now.
I am trying to get some more grips on AS2.0 and do this by making a small game. On several frames are movieclips: mc1 mc2 etc. When the user clicks on them, the total number of clicks is recorded (among others) for each movieclip. On different frames are different movieclips. I tried three ways.
1. First I defined a class MyMovieClipClass extends MovieClip with: code: private var clicks: Number private function onPress: Void { clicks++; // do other things } public function howMuch: Number{ // return clicks }
Movieclips mc1, mc2, etc are defined being a member of this class in ‘linkage’. The problem arose that when on a frame without mc1 I could not access mc1.howMuch() becase in that frame there is no mc1.
2. Then I defined two classes MyMovieClipClassA and MyMovieClipClassB The movieclip on stage mc1 is a member of Class A and var clicks is in Class B. The instance name of class B is derivated from the instance name on stage: mc1 (ClassA) is kindof connected with mc1_obj (ClassB) MyMovieClipClassA extends MovieClip with: code: private function onPress: Void { // make instName = this._name + “obj”; instName.clicks++; // do other things }
MyMovieClipClassB with: code: private var clicks: Number public function howMuch: Number{ // return clicks }
In the timeline I then define: code: var item1: MyMovieClipClassA = new MyMovieClipClassA(); var item1_obj: MyMovieClipClassB = new MyMovieClipClassB();
which is not very elegant. (the movieclip to which this belongs has the name item1)
3. I tried to declare ‘_name + “_obj”’ in de constructor of ClassA but did not succeed.
Anybody any suggestions for an elegant solution in which different movieclips in different frames on stage can be tracked using classes? Thanks in advance for your reaction.
FlashKit > Flash Help > Flash ActionScript
Posted on: 12-03-2005, 09:54 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
AS2 - Best Way To Extend MovieClip Class?
What is the best/proper way for an AS2 Class to extend the MovieClip Class, to allow access to its methods (i.e. 'attachMovie()')?
Is it possible for an AS2 Class to access MovieClip methods w/o extending the MovieClip Class?
Thanks for any advice.
Extend MovieClip Class
I would like to write some clips, but it seems do not work.
my test.as file:
class test extends MovieClip {
function test() {
this.lineStyle(1, 0xff0000, 100);
this.moveTo(50,50);
this.lineTo(111,111);
}
}
code in first frame script:
var aline;
aline = new test();
stop();
Why the clip does not draw anything!?
But if i modify the class definition as follows:
class test extends MovieClip {
var mc;
function test() {
this.mc = _root.createEmptyMovieClip( "mc1", 10);
this.mc.lineStyle(1, 0xff0000, 100);
this.mc.moveTo(50,50);
this.mc.lineTo(111,111);
}
}
evrything is ok.
So, must be create a property and assign a new mc to it,
or it possible to use simply the this. object for drawing ?
Thanks if someone could help.
Extend MovieClip Class
I want to add a property to the MovieClip class that tells me if the object is draggable or not.
I tried to do this:
Code:
class MovieClip extends MovieClip
{
public var _draggable:Boolean;
}
But this doesn't work.
I tried to add:
Code:
class MovieClip extends MovieClip
{
public var _draggable:Boolean;
this.prototype._draggable = true;
function isDraggable():Boolean
{
return _draggable;
}
}
But it still doesn't work.
What I need to write?
How To Extend Movieclip Class ?
OK, I understand that I could create a separate *.as file that contain within it drawing functions to draw a shape out and in that class create within it static variable or just plain public variables for example each "Player" object have a direction, speed and such.
It would be no problem if the player is just merely objects that can be drawn with codes.
But...what if it's an image ?
I would import the image in flash, make it into a movie clip, give the clip a class name through the "Linkage" option and now I have the "Player" Class with the imported image I need....it's all good...but I don't want the "Player" class to just contain an image, I want to give it internal properties.
I presume I could do things like these in the first frame of the timeline:
ActionScript Code:
class Player_with_properties extends Player
{
public var PlayerDirection:int = 0;
public var PlayerSpeed:int = 0;
public function Player_with_properties()
{
trace("Constructor Initialized.");
}
}
But nooooo...Actionscript 3 says "Classes must not be nested.".
All I hear is, Ha Ha Ha from the Actionscript three....
So how do I create a class with image and properties ?
When To Extend The MovieClip Class
1) When your class is used to produce anything visual (Put mc's on the stage)
2) When any part of your class needs to use a property, event, or method of the MovieClip class
Do I have this correct?
AS3.0: How To Extend A Class That Extends MovieClip
When I try to set the base class of a library symbol to a class that doesn't DIRECTLY extend MovieClip, but instead extends another class that DOES extend MovieClip, it's disallowed, saying, "The class 'Whatever' must subclass 'flash.display.MovieClip' since it is linked..."
Is this just a validation bug in the property windows, only checking one class deep into the inheritance hierarchy? Because the specified class does extend MovieClip, just two levels in instead of one. Is there a fix for this? Or must library symbols always directly extend MovieClip? If so, why?
Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?
When Making A Document Class Should You Extend MovieClip Or Sprite?
When creating a project with a Document Class should your Document Class extend MovieClip or Sprite?
It seems that if your Fla uses the timeline and contains more than a single frame you'll need to extend MovieClip.
If your fla uses only one frame Sprite might be the better choice. But, are there cases where you might want to use MovieClip still?
Any project could be built around either base Class, MovieClip or Sprite, is one a better choice than the other? It seems MovieClip uses more memory, but is this enough of an issue to make it a best practice?
I'm just getting up to speed with this AS3 stuff and was looking for some thoughts on the subject.
How To Target A Movieclip Within A Movieclip On The Stage (in A Class)
Peepz,
Im building a scroll class which looks like this:
ActionScript Code:
package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.Event; import flash.geom.Rectangle; import flash.display.DisplayObjectContainer import flash.display.MovieClip; public class ContentScroller2 { //eigen code private var moveSpeed:Number private var easingSpeed:Number private var scrollHeight:Number private var percentScrolled:Number private var newY:Number // how much of the movie can be scrolled private var scrollable:Number private var initContentPos:Number // the drag positions that are possible for the mcDragger private var left:Number private var top:Number private var right:Number private var bottom:Number private var scrollWheelSpeed:Number private var _mcContent:Sprite private var _mcMask:Sprite private var _mcDragger:Sprite private var _mcTrack:Sprite private var dragBounds:Rectangle; public function ContentScroller2(mcContent:Sprite, mcMask:Sprite, mcDragger:Sprite, mcTrack:Sprite, ease:Number, setDraggerSize:Boolean = false) { _mcContent = mcContent _mcMask = mcMask _mcDragger = mcDragger _mcTrack = mcTrack moveSpeed = 2; easingSpeed = 5; scrollHeight = _mcTrack.height ; // how much of the movie can be scrolled scrollable = Math.round(_mcContent.mcRegister.height - mcMask.height); initContentPos = 12 // the drag positions that are possible for the mcDragger left = _mcTrack.x; top = _mcTrack.y + 26; right = _mcTrack.x; bottom = _mcTrack.height - _mcDragger.height + _mcTrack.y scrollWheelSpeed = 30; dragBounds = new Rectangle(_mcDragger.x, _mcDragger.y, 0, _mcTrack.height - _mcDragger.height); initHorizontal(); } private function initHorizontal():void { // before we do anything make sure the content is even scrollable, if it isn't hide everything and return if (scrollable<0) { _mcDragger.visible = false; _mcTrack.visible = false //btnDown.enabled = false; return; _mcContent.removeEventListener(Event.ENTER_FRAME, updateContentPos); } else { addListeners(); } } private function addListeners():void { _mcDragger.addEventListener(MouseEvent.MOUSE_DOWN, draggerDown); _mcDragger.addEventListener(MouseEvent.MOUSE_UP, removeDraggerEvents); } private function draggerDown (me:MouseEvent):void { _mcDragger.startDrag(false, dragBounds); _mcDragger.addEventListener(MouseEvent.MOUSE_MOVE, draggerMouseMove); //_mcContent.addEventListener(Event.ENTER_FRAME, updateContentPos); } private function draggerMouseMove (me:MouseEvent):void { updateContentPos(); } private function removeDraggerEvents (me:MouseEvent):void { _mcContent.removeEventListener(Event.ENTER_FRAME, updateContentPos); _mcDragger.removeEventListener(MouseEvent.MOUSE_MO VE, draggerMouseMove); _mcDragger.stopDrag(); } private function updateContentPos ():void { percentScrolled = (_mcDragger.y-top)/(scrollHeight-_mcDragger.height); // instead of setting the _y property directly, we simple set newY // that way we can adjust how we handle the new Y coordinate we'd like to move to newY = Math.round(initContentPos-(percentScrolled*scrollable)); trace(percentScrolled) _mcContent.y += Math.round((newY-_mcContent.y)/easingSpeed); } }
i have a code inside my total movie which contains the scroller, the code is:
ActionScript Code:
var myContentScroller:ContentScroller2 = new ContentScroller2(mcContent, mcMask, mcDragger, mcTrack, 3, false)
All the clips like: mcContent, mcMask, mcDragger, mcTrack are on the stage.
To use this MC's well i have to (or maybe not) i have to "re-assign" them in the package like (maybe there is a cleaner and better way?):
ActionScript Code:
_mcContent = mcContent _mcMask = mcMask _mcDragger = mcDragger _mcTrack = mcTrack
but now my final question is how can i target the movieClip "mcRegister" which is inside "mcContent" on the stage? (in AS1 it was like mcContent.mcRegister but that wont work.)
the code in the package is like:
ActionScript Code:
scrollable = Math.round(_mcContent.mcRegister.height - mcMask.height);
Hope somebody can help me out!
Greetz!
Duplicating MovieClip On Stage From A Class
Hey All,
say I have a main MC (linked to a Main Class) on the stage and inside of that I have an MC sitting offstage (called shot...has a Class linked to it (called Laser) and Main does have a reference to that Class). Say in Main when the mouse is clicked I want it to duplicate that "shot" MC. How would I do that?
This is not working:
Main.as
mouseListener = new Object();
Code:
mouseListener.onMouseDown = function ()
{
this.duplicateMovieClip("laser_mc","shot",5000);
this.shot._x=111
this.shot._y=111
trace("MOUSE FIRE!");
}
the trace is working but it is not duplicating the clip.
Thanks, Dvl
How Do I Get The Stage Size Of A Movieclip From Within A Class
Hi Guys,
I have a movieclip and a class attached to it.
In the class I have a simple trace to return the size of the
movieclip's stage. when I attach the movieclip into the stage I
get
Error #1009: Cannot access a property or method of a null object reference.
Why is that? and how can I get the stage width of a mc from a class.
that's what I have been using:
ActionScript Code:
trace(this.stage.stageWidth);
thanks
[CS3] Adding A MovieClip To The Stage From A Class Function
Of course, it's easy enough to do when not working with classes. Basically, I want to be able to execute a function from one of my classes that does the following -
Code:
function buildArea():void
{
var i:Number = 1;
this[ "tile_" + i ] = new TileSet01(); // a for-loop will be used later, so this is necessary
addChild( this[ "tile_" + i ] );
}
buildArea();
If I remember correctly, I did this in AS2 using Delegates. Unfortunately, it doesn't seem to work the same way in AS3...
Access A MovieClip On The Stage From Default Class.
Hi how do I access a movie clip in my library (using FLash CS3), that is already on the timeline, on the stage from the Default class so I can change its properties with script ?
I have a movie clip containing an image (mcMan) that is dynamically added to the stage as below in the Default class. I added it dynamically so I could do a transition :
Code:
private function onManEveryFrame(event:Event):void
{
if (this.currentLabel == "enterMan")
{
man.removeEventListener(Event.ENTER_FRAME, onManEveryFrame);
//add man to stage
tMgr = new TransitionManager(man);
addChild(man);
man.x = 0;
man.y = 0;
tMgr.startTransition({type:Blinds, direction:Transition.IN, duration:.9, easing:None.easeOut, numStrips:20, dimension:0});
}
}
Thats fine and all but on the stage itself I have another movieclip from the library called mcTree again containing a single image I want to animate. This uses a motion tween but unfortunately is appearing on top of the mcMan movieclip above when I publish the movie.
I tried
this.setChildIndex(man, this.numChildren - 1);
to put the man at the top index but still the tree is in front of the man. I was thinking if I could access the instance object (or whatever) of mcTree on the stage I could use something like
this.swapChildren(tree, man);
At the moment I didnt give the mcTree movie on the stage an instance name as there are 3 keyframes using the same mcTree and I want to talk about the same object (mcTree). Should I give them all the same instance name? Very confused, must have missed something basic. Wasted a good few hours on it already
many thanks for any ideas or links.
[AS3] Adding A MovieClip To The Stage From A Class Function
Of course, it's easy enough to do when not working with classes. Basically, I want to be able to execute a function from one of my classes that does the following -
Code:
function buildArea():void
{
var i:Number = 1;
this[ "tile_" + i ] = new TileSet01(); // a for-loop will be used later, so this is necessary
addChild( this[ "tile_" + i ] );
}
buildArea();
If I remember correctly, I did this in AS2 using Delegates. Unfortunately, it doesn't seem to work the same way in AS3...
Adding MovieClip To Stage From As3 Class File
Hello,
Does flash have an equivalent to Flex's Application.application.[insert application method or property here]?
I want to get access from an as3 class file to the main stage. a call to this.root from the stage to the class will not work because I need the root object stage to execute an addChild method. Can you help?
Best,
Richard
Attach Code
package com.custom.text.effects {
// Import the required transition classes.
import flash.display.MovieClip;//import movieclip class
import flash.display.Stage;//import stage access
import flash.text.*;//import all text classes
import fl.transitions.easing.*;//import all easing types
import fl.transitions.*;//import all transitions
public class textEffects {
//create the constructor
public function textEffects(strText:String = "")
{
strText = strText;
}
//declare the properties
public var strText:String;
public function FlyBlind(strText:String) {
// Create a new instance of the Font1 symbol from the document's library.
var myFont:Font = new Trebuchet();
/* Create a new TextFormat object, and set the font property to the myFont
object's fontName property. */
var myFormat:TextFormat = new TextFormat();
myFormat.font = myFont.fontName;
myFormat.size = 24;
/* Create a new TextField object, assign the text format using the
defaultTextFormat property, set the embedFonts property to true, set
the antiAliasType property to "advanced", and rotate the text field. */
var myTextField:TextField = new TextField();
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.embedFonts = true;
myTextField.antiAliasType = AntiAliasType.ADVANCED;
myTextField.textColor = 0x004B8E;
myTextField.defaultTextFormat = myFormat;
myTextField.text = strText;
myTextField.border = false;
myTextField.x = 115;
myTextField.y = 205;
//myTextField.rotation = 15;
var myMovieClip:MovieClip = new MovieClip();
myMovieClip.addChild(myTextField);
//this line doesn't work yet - the finishing line
// if I try to use the root of myMovieClip I'll get an error because it's not added to the stage
// to have an assigned root value, it must be assigned to the root
{this}.root.addChild(myMovieClip);//an attempt to add myMovieClip to the scene
//list of all possible transitions with example
TransitionManager.start(myMovieClip, {type:Blinds, direction:Transition.IN, duration:2, easing:None.easeNone, numStrips:10, dimension:0});
//TransitionManager.start(myMovieClip, {type:Fade, direction:Transition.IN, duration:9, easing:Strong.easeOut});
TransitionManager.start(myMovieClip, {type:Fly, direction:Transition.IN, duration:3, easing:Elastic.easeOut, startPoint:9});
//TransitionManager.start(myMovieClip, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:5, shape:Iris.CIRCLE});
//TransitionManager.start (myMovieClip, {type:Photo, direction:Transition.IN, duration:1, easing:None.easeNone});
//TransitionManager.start(myMovieClip, {type:Rotate, direction:Transition.IN, duration:3, easing:Strong.easeInOut, ccw:false, degrees:720});
//TransitionManager.start(myMovieClip, {type:Squeeze, direction:Transition.IN, duration:2, easing:Elastic.easeOut, dimension:1});
//TransitionManager.start(myMovieClip, {type:Wipe, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
//TransitionManager.start(myMovieClip, {type:Zoom, direction:Transition.IN, duration:2, easing:Elastic.easeOut});
}
}
}
How Do You Make A Movieclip On The Stage A Property Of A Class?
I have a class with a movieclip as one of it's properties. In a FLA if I dynamically add the property to the class it works fine but if I explicitly declare it as a property in the class it throws a null object reference exception when I try and access it.
What am I missing or misunderstanding here?
Accessing Variable And Method In A Class From A Sub Movieclip On Stage?
Folder structure.
root_folder/site.fla
root_folder/hdg/HDGClass.as
I have the document class set to hdg.HDGClass and there are 3 movie clips on the stage with the instance names btn1, btn2, and btn3 and each have a submovie clip with the instance name btn.
HDGClass.as
Code:
package hdg {
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.*;
import flash.events.*;
import flash.errors.*;
public class HDGClass extends MovieClip {
public var currentNav:int = 1;
public function HDGClass():void {
init();
}
public function init():void {
//initialize top navigation buttons
btn1.btn.addEventListener(MouseEvent.MOUSE_OVER, topNavOver);
btn1.btn.addEventListener(MouseEvent.MOUSE_OUT, topNavOut);
btn1.btn.addEventListener(MouseEvent.MOUSE_DOWN, topNavClick);
btn1.btn.buttonMode = true; //gives movieClip the hand cursor
btn2.btn.addEventListener(MouseEvent.MOUSE_OVER, topNavOver);
btn2.btn.addEventListener(MouseEvent.MOUSE_OUT, topNavOut);
btn2.btn.addEventListener(MouseEvent.MOUSE_DOWN, topNavClick);
btn2.btn.buttonMode = true;
btn3.btn.addEventListener(MouseEvent.MOUSE_OVER, topNavOver);
btn3.btn.addEventListener(MouseEvent.MOUSE_OUT, topNavOut);
btn3.btn.addEventListener(MouseEvent.MOUSE_DOWN, topNavClick);
btn3.btn.buttonMode = true;
}
function topNavOver(event:MouseEvent):void {
event.target.parent.gotoAndPlay(2);
}
function topNavOut(event:MouseEvent):void {
event.target.parent.gotoAndPlay(34);
}
function topNavClick(event:MouseEvent):void {
currentNav = event.target.parent.id_txt.text;
}
function yo() {
trace("yo");//test function
}
}
}
frame 1 of my root timeline just has...
Code:
stop();
on frame 34 of btn1, btn2, and btn3 there is this code just to test if the variable or test methods can be retreived/called.
Code:
trace(currentNav);
yo();
The mouse events work fine triggering the mouse_over and mouse_out and mouse_down actions. But when I added the above code to frame34 I get these errors...
1120: Access of undefined property currentNav.
1120: Access of undefined property yo.
How do I access them correctly?
I tried adding this to frame1 of my root timeline just to do another test but still got errors....
Code:
var x:HDGClass = new HDGClass();
x.yo();
trace(x.currentNav);
Adding Instance To Stage From A Movieclip Linked Class
Hi,
I was trying to add an instance I created in a class to the main
stage, like this:
Code:
var blackD:MovieClip = new blackboardinfo();
Stage.addChild(blackD);
it was working fine, however, after I added preload page, which will now
load everything else as external swf, i began getting this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I tried to modify the code to this based on the similar questions i found online
Code:
var mc:MovieClip = new MovieClip();
addChild(mc);
var _stage:Stage = mc.stage;
_stage.addChild(blackD);
I still get the same error, I know it is because "stage", but if I dont use stage, how
can I add an instance on top of everything? thanks.
Extend Movieclip
I know how to attach a class to a movieclip via the linkage dialog, but how can I do it if I create the movieclip by createEmptyMovieClip(); ?
any help on this would be greatly appriciated
Call Function, Pass Value, Access Variable In Movieclip Class From Main Stage
i am new to flash as.
I got quite confused on some problems. as the function here is quite different from c and asp.net.
I have a movieClip named MC, and it's enabled with action script, with the class name MC_Rectangle
and a Stage.
I override the MC_Rectangle class file in a mc_rectangle.as external file.
here is the code:
package{
import flash.display.*;
import flash.events.*;
public class MC_Rectangle extends MovieClip {
var sequence:int = new int();
function setSequence(data:int):void{
sequence = data;
...
}
function addSequence():void{
sequence ++;
...
}
...
}
}
I have new a object in the main stage var mc_rect:MC_Rectangle = new MC_Rectangle()
question:
in main stage:
1. how can i access the variable "sequence" in "mc_rect"
2. how can i pass parametre from main stage to mc_rect via function setSequence(data:int)?
3. how can i call the function in addSequence() in mc_rect.
in asp.net, i usually use mc_rect.sequenct, mc_rect.setSequence(data), mc_rect.addSequence() to achieve my goals......
btw, can function in mc_rect return out result to main stage?
thanks in advance.
Extend MovieClip After It's Created?
Is it possible to do something like this:
var mc:MovieClip = new MovieClip();
mc.applyClass('someclass');
Something like that? Sometimes I want to just apply utility methods to a movieclip without having to create a special type of movieclip.
Also, is it possible to extend the movieclip class for all movieclips to add global utility stuff?
.as File To Extend Movieclip
I'm learning how to create preloaders for my flash files. I'm looking at the tutorial on the Macromedia site
http://www.macromedia.com/devnet/mx/...preloader.html
I'm using Flash MX 2004 Pro and the file won't work when I export for the following error.
Quote:
**Error** Symbol=preloader_mc, layer=text, frame=1:Line 1: The class 'Preloader' could not be loaded.
Total ActionScript Errors: 1 Reported Errors: 1
The tutorial provides the preloader.as file but I don't know where to attach the file to get the exported swf to work. I have checked the fla and the linkage is set in the library for the preloader_mc.
Loading A Movieclip On The Main Stage From A Button Within A Movieclip - Big Headache
Hi there,
i am trying to put together a portfolio site, which uses a 'floating' panel with buttons on it. In order for it to move around it has to be a movieclip. So all the buttons are stored within a single movieclip, which is giving me a headache because i want those buttons to load other movieclips from my library onto the main stage (as like a popup window within the flash)
Its all slightly confusing. i have tried using this code based within the movieclip where my button is based:
button_play.buttonMode = true;
button_play.addEventListener(MouseEvent.CLICK, OpenBox);
function OpenBox (e:MouseEvent):void{
this.addChild(new mc_box());
}
button play is within a movieclip called mcTweenMe2 (which is on the main timeline) and i want the movieclip to be loaded on the main timeline (not within in the movieclip where the button 'button_play' is based) mc_box is the movieclip i wish to load on the main timeline (in the centre) with the ability to close it also!
Bit of a headache, please help me someone i have run out of sites to look for answers!
PS: does anyone know why stop (); wont stop my timeline playing like it used to in AS2? beacause another option for making my site work is making this button target labeled frames in the main timeline, however stop (); don't seem to work now!
Thanks!
Flash Actionscript 3.0 Extend MovieClip
Not sure if this message should be here but I don't see an actionscript 3.0 section in the Flash area yet so here goes. I want to create a chess game. I have animated pieces in the library. It looks like actionscript creates a new class for each symbol in the library? What I want to do is create a gamepiece class that I can do something like this.
var gamePiece_01:GamePiece = new GamePiece("instanceName in Library");
I want to then be able to manipulate the game piece on the stage...
ie...gamePiece.move(Square_01, Square_05);
If I can get the display object to be created in the GamePiece class by just passing it the instance name from the library it would be great!
I've seen ways to do this if I was going to create a shape but not if I want ot use something in the library.
Could someone please shed a little light on this for me?
THANKS!!!
How To Extend MovieClip And Treat OnRollOver
with the example below I want to achieve an rollover effect switching JPGs,
I get the first image on the stage but no events sensing at all.
I´d like to understand the canonical OO way to do the right.
any help ? thanks
Joao Carlos
ActionScript Code:
class BotaoImgExt extends MovieClip
{
private var _mc:MovieClip;
var _imgOver:String;
var _imgOut:String;
//
public function BotaoImgExt(imgOut:String, imgOver:String, mcTarget:MovieClip, x:Number, y:Number)
{
this._imgOver = imgOver;
this._imgOut = imgOut;
_mc = mcTarget.createEmptyMovieClip("mcHolder", mcTarget.getNextHighestDepth());
_mc.createEmptyMovieClip("holderJPG", 1);
_mc.holderJPG.loadMovie(_imgOut);
_mc._x = x;
_mc._y = y;
}
function onRollOver()
{
trace("over");
_mc.holderJPG.loadMovie(this._imgOver);
}
function onRollOout()
{
trace("out");
_mc.holderJPG.loadMovie(this._imgOut);
}
}
Clarification Of Senocular FAQ Regarding Classes Which Extend MovieClip
I'm interested in created a superclass with supporting subclasses where the superclass extends MovieClip. I'm familiar with assigning an AS 2.0 class to a linked library MovieClip. I was interested in generating the clip dynamically and associating it with said superclass. So, I started hunting down information on doing just that and ran across Senocular's FAQ item about why extending the MovieClip class is different.
In Senocular's tutorial FAQ, he explains how to avoid using attachMovie and an init private function with a class in this fashion:
Quote:
It is also not uncommon to have a static create method in your class to generate movie clip instances for you. Having such a method lets you avoid any confustion that might result in using attachMovie as well as provides you a means to pass all arguments for instantiation into one function call as opposed to 2, which is what you get with attachMovie + init.
His code sample is as follows:
Code:
class MyClass extends MovieClip {
static var symbolName:String = "MyClassLinkageID";
static function create(timeline:MovieClip, name:String, value1:Number, value2:Number):MyClass{
var instance = timeline.attachMovie(symbolName, name, timeline.getNextHighestDepth());
// use value1 and value2 as you would in the constructor only on 'instance' and not 'this'
return instance;
}
function MyClass(){
// no arguments passed
}
}
However, he notes:
Quote:
Note that a depth parameter was omitted in favor of having the new instance's depth controlled from within the create method. It could have just as well been passed with the others of the values. The same also applies to the movie clip linkage. However, if you plan to use more than one movie clip symbol, you would need to make sure you use Object.registerClass to associate the class to each symbol before using attachMovie.
What does the comment about using Object.registerClass mean? I'm still going to have a movieclip in my library with a linkage to use the code above, right? Would I not also then associate my AS 2.0 superclass to said linked library item?
Senocular -- you answered a similar question from me earlier this week, I think. 'ppreciate any clarification you might have on the above. If anyone else has this same sort of question, read his FAQ/tutorial on the subject:
http://www.senocular.com/flash/tutor.../#newmovieclip
Thanks,
IronChefMorimoto
Displaying Custom Classes That Extend MovieClip In Flash CS3
I'm pretty new to Flash CS3 and Actionscript 3, and I have just come over from Java so please bare with any knowledge shortcomings I'll most likely have...
I'm trying to create a simple game and to do so I'd like to have a custom class that extends the MovieClip class and can do such things as move and play a move animation, shoot, etc.
So I created a class called Player extended it off of MovieClip, and supplied all the necessary code. The only problem is I can't figure out how to create a graphic that is an instance of my Player class in Flash CS3... To sum it up I want to create a symbol that is not an instance of Button, Graphic, or MovieClip, but of Player.
I can make a regular symbol of a MovieClip class do all the stuff I need by frame scripting... but I rather not frame script an entire game due to the obvious organizational havoc.
I have been researching this problem and I had thought that Linkage was my solution but when I tried to put that into practice I couldn't get what I wanted out of it... Was I on the right track, and just couldn't figure it out completely?
Thanks in advance for any help in the matter...
Load Movieclip From Library Into A Movieclip On The Stage?
Alright I am losing my mind trying to figure out something so simple, I can load external swfs no problem, but How do you access a movieclip from the library?
I have a main swf, and a movieclip in the library named feb93_mov. Basically I want to on MOUSE_DOWN load the library item "feb93_mov" into swfloader_mc on the stage. But I cant write an instance name for "feb93_mov" cause it's not supported, so how do I access it then?
Here is my code what is wrong with it?:
ActionScript Code:
feb93_btn.addEventListener(MouseEvent.MOUSE_DOWN, feb93down);
function feb93down(event:MouseEvent):void
{
loadMe4();
}
var loadMe4 = function():void
{
var feb93_mov:MovieClip = new MovieClip();
swfloader_mc.addChild(feb93_mov);
}
[CS3] Referencing A Movieclip Inside A Movieclip From A Class File
Hello All,
I'm trying to access a movieclip inside another movie clip from a class file that is not attached to either movieclip. For instance, I'm checking hitTests for the avatar the player uses on the game, there are two enemy movieclips. Inside each enemy movieclip is another movie clip that serves as a bounding box (specifically around the mouth of the enemy so it can eat the player). Here is what I have so far that isnt working:
Code:
if (_root['otter']['obbox'].hitTest(this) && touch == false) {
trace("Otter touched Urchin");
gotoAndPlay("hit");
_root['otter'].gotoAndPlay("eat");
touch = true;
}
The class file is for the avatar. On the stage is the otter mc and inside the otter mc is another mc called obbox which is what I'm trying to hitTest against. Needless to say, it doesn't hitTest or trace or play the animation. Is there a way to reference a nested mc? Thanks in advance.
Terror.
Exending Movieclip Class With Your Own Movieclip And How To Create Children In It.
I was writing actionscript for a custom movieclip class I made.
Created my movieclip in flash and linked it as Dude class.
One question: Is it possible to override the constructor? I tried to do it but flash gives me an error "duplicate function definition"
Another question: How do I create a displayobject in this movieclip? I tried to do something like this inside the actionscript for the Dude movieclip.
Code:
var mytext:TextField = new TextField();
// code to change textfield's properties
addChild( mytext );
But when I created an instance of Dude on the stage the textfield isn't showing.
Getting A MovieClip Into A Custom Class Extending MovieClip
I have class that extends movie clip, but I can't seem to find a way to turn an existing movie clip into the class.
Here's the class:
Code:
package
{
import flash.display.Stage;
import flash.display.MovieClip;
public class Character extends MovieClip
{
private var stageReference:Stage;
private var characterMovieClip:MovieClip;
public function Character(inputStageReference:Stage, inputMovieClip:MovieClip):void
{
stageReference = inputStageReference;
characterMovieClip = inputMovieClip;
this = characterMovieClip;
trace("character instantiated");
}
}
}
The "this = characterMovieClip;" obviously creates a problem, but how else could I do this?
I've tried casting an existing MovieClip to the Class, which also doesn't work.
Thanks!
[CLASS] AddChild(MovieClip) + MemberFunctionTween(MovieClip)
Hi guys im a graduate in computer science as of last semester. Im trying to design a simple portfolio website using as3. i know languages like c++, vb, java, sql but never got the chance to explore the world of actionscript, so im kindov teaching it to myself. dont have any books yet, just scouring the internet for some snippets.
I have uploaded a zip folder of my .fla and my .as class file. atm all i want to see is the movie clip that i have called "Navigation" be added to the stage via addChild() and be tweened in/out using the two temp buttons i have directly placed on the stage via member function call with predefined coordinates from constructor function.
for the elite who dont need to dl my files
This is my .fla code
Code:
//import GPS;
//stage.frameRate = 50;
//stage.height = 100%; //yah this is another problem i have is 100% both ways
//stage.width = 100%;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//istantiating the class with test construction parameters
var Nav:GPS = new GPS(Navme, 100, 100, 500, 500, 20);
//\== is the class name i gave the movie clip via
// right clicking in library and goin to linkage
// selecting export for actionscript and typing this
//name in the "Class" field
//two buttons to test the tweenIn and tweenOut member functions
b1.addEventListener(MouseEvent.CLICK, getin);
b2.addEventListener(MouseEvent.CLICK, getout);
function getin(event:MouseEvent)
{ //on first button want it to tween onto stage
Nav.TweenIn();
trace("in getin");
}
function getout(event:MouseEvent)
{ //on second button want it to tween off stage
Nav.TweenOut();
trace("in getout");
}
and this is my .as class code
Code:
package actionscript3
{
import flash.display.MovieClip;
public class GPS extends MovieClip
{
//imports
import fl.transitions.easing.*;
import fl.transitions.Tween;
private var SCoordX:Number; //member variables
private var SCoordY:Number;
private var ECoordX:Number;
private var ECoordY:Number;
private var Time:Number;
var myPositionTween:Tween;
private var OBJClass:Class;
private var mc:MovieClip;
//import flash.display.Loader; //other things that i attempted to use
//var my_loader:Loader = new Loader();
//var my_mc:MovieClip = new MovieClip();
public function GPS(Navme:Class, StartX:Number, StartY:Number, EndX:Number, EndY:Number, Seconds:Number)
{
setCoords(StartX, StartY, EndX, EndY);
Time = Seconds;
mc = new Navme(); //here is my attempt to addChild() i make a new Movie Clip with the class name
stage.addChild(mc); //then add it to stage right?
mc.x = 300; //then move it onto the stage?
mc.y = 300;
}
public function TweenIn():void
{
myPositionTween = new Tween(mc, "x", Strong.easeOut, getECoordX(), getSCoordX(), getTime(), false);
myPositionTween = new Tween(mc, "y", Strong.easeOut, getECoordY(), getSCoordY(), getTime(), false);
}
public function TweenOut():void
{
myPositionTween = new Tween(mc, "x", Strong.easeOut, getSCoordX(), getECoordX(), getTime(), false);
myPositionTween = new Tween(mc, "y", Strong.easeOut, getSCoordY(), getECoordY(), getTime(), false);
}
public function getMC():MovieClip //for stack use later on, push all movieclips onto stack, then
{ // will pop remove them from stage
return mc;
}
public function getTime():Number
{
return Time; //integral for tween
}
public function setCoords(StartX:Number, StartY:Number, EndX:Number, EndY:Number):void
{
SCoordX = StartX; //this will be used to tell the movieclip where to go
SCoordY = StartY; //static atm, will be randomized later
ECoordX = EndX;
ECoordY = EndY;
}
public function getSCoordX():Number
{
return SCoordX; //gana have a movieclip on the stage follow new objects
} // and know when the appearence of "Sittin On Top Of" is true
public function getSCoordY():Number
{
return SCoordY;
}
public function getECoordX():Number
{
return ECoordX;
}
public function getECoordY():Number
{
return ECoordY;
}
}
}
i right clicked the navigation movieclip into library and went to linkage and gave it a class name of "Navme". u can also find some other things that i have tried that are commented out in the code.
The code i have now doesnt have any errors, and no child is added to the stage so its kindov got me in between a rock and a hard place because i cant google any error description. can someone plz help me?
thx
jay
Load Movieclip Into A Movieclip On Stage
On the loading of my page, I need to load an english text movieclip into one that's on stage. Also on stage is a button to push for the Japanese translation. When this button is pushed, I need to load the japanese movieclip into the place where the english version is and for the english to go away. How do I do this?
Movieclip Referencing Another MovieClip On Stage
Hi all,
I have a movieclip with dynamically loaded content in a movieclip that sits on the stage, which works fine, it loads the content fine. Call it Clip A
I want multiple movieclips to reference this movieclips content. ie I want a copy of this Clip A to appear in multiple movieclips.
Real example
Clip A loads teamshirt Arsenal
Multiple clips to also have Arsenal teamshirt by looking at ClipA
Any ideas? Do i go about it using loadMovie and pointing it to the scene or attachMovie?
thank you in advance
Jason
[f8]Loading A MovieClip From Another MovieClip In The Stage
Hi, i just learn flash and AS and now i am trying to build a menu with submenu.
I have 2 files :
a. loader.swf
b. menu.swf
Condition :
1. Loader.swf has a button that loads menu.swf into stage via createEmptyMvieClip.
2. Menu.swf have sets of button that supposed to load a jpeg/clip to Loader stage which acting as a "submenu".
And my question is :
Is it possible to load a clip from a loaded menu.swf into Loader.swf stage?
I have this code that individually works but not when i load the menu.swf. The map.swf won't load into Loader stage.
Code:
== loader.swf ==
_root.createEmptyMovieClip("menu",0);
menu.loadMovie("menu.swf");
Code:
== menu.swf ==
btn1.onPress = function () {
_root.createEmptyMovieClip("container", 1);
container.loadMovie("new_mohome/map.swf", 2);
}
btn2.onPress = function () {
_root.createEmptyMovieClip("container", 1);
container.loadMovie("new_mohome/map.swf", 2);
}
btn3.onPress = function () {
_root.createEmptyMovieClip("container", 1);
container.loadMovie("new_mohome/map.swf", 2);
}
Accessing A MovieClip On The Stage From Within Another MovieClip
Hi, after many hours searching through many forums and posts im still not finding the answer to what should be pretty simple to achive. If anyone has an idea please do tell me.
Problem is this:-
I have two movieClip's on a stage (on the main timeline). Called 'box4_mc' and 'fadeSquare_mc'. Inside 'box4_mc' on its timeline (but only on frame 54) is a button called 'close4_btn'. When I click on 'close4_btn' I want 'fadeSquare_mc.play();' to work. The actionscript code has to go on the 'box4_mc' timeline because the button doesn't exist to the main timelime. I have attached a .fla file zipped up as an example. I have tried the following:
Code:
this.parent.fadeSquare_mc.play();
and also
Code:
this.fadeSquare_mc.play();
the first gives an error 1119: Access of possibly undefined property fadeSquare_mc through a reference with static type flash.displayDisplayObjectContainer.
the 2nd gives
TypeError: Error #1010: A term is undefined and has no properties.
at boxes4a_fla::box4_12/closeBox4()
im at a loss what to do.
Thanks in advance.
Class MovieClip Extends MovieClip
Hey guys, I was just wondering if there is any easy way to extend the MovieClip class itself, without making a new class? I'd like it to be equivalent to using MovieClip.prototype ... or should I just use prototype?
-Matt
F8 Movieclip Change On Stage Causes The Entire Stage To Dissapear
I have my stage with a background picture.
On stage left are buttons, and on stage right I have a movieclip (mc_Preview).
When the user puts his mouse over each button I would like the movieclip to move to a different frame.
the problem is when the mouse moves over a button, i see the movieclip move but then the entire stage dissappears and turns a few shades of gray.
Does this sound familiar to anyone?
Any help would be greatly appreciated!
Call Function Of Document Class From MovieClip Class
How can I run a function of the main document class from a class of a MovieClip? I usually just used MovieClip(parent).function(), but now my MovieClip has another parent. Or what do I have to pass to the MovieClip class when creating the MovieClip to acess the main document class?
Class's Movieclip Calling A Function In It's Own Class
For the life of me I can't find an internet source that explains why this doesn't work. I know it's a scope problem but I know no other way around it and there must be a way to do it, I'm thinking.
I have a class. Inside this class I create a movieclip which I have a class variable link to. The movieclip is created on _root. When I click on this movieclip, I want it to call a function inside the class. Here's what it looks like.
Code:
class Whatever extends Movieclip {
private var mc:MovieClip;
public function Whatever() {
this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextHighestDepth());
[code for drawing a square]
this.mc.onPress = this.doSomething();
}
public function doSomething {
[do something]
}
In the above sample, when I click on the movieclip, the "doSomething" function is not called, obviously because the movieclip is on root and has nothing to do with the class. Is there a way to do what I want to do?
Assigning A Class MovieClip An Additional Class
normally if i wanted to add a class movieclip i would do something like:
var newChar:specificChar = new specificChar();
this.addChild(newChar);
Now is there a way where I could declare newChar to become a player or AI by adding another class to it.
Put Movieclip On Stage
this sounds stupid but i've always put stuff on the stage by having it just outside the visible screen and duplicating it onto the stage.
here's my problem:
I've got an instance of a MC off the stage. It's got some code which makes it move etc... if i duplicate it all the duplicates move fine. problem is the original moves as well. and goes flying off to infinity. i haven't put any boundary conditions in because they would remove the original MC an i wont be able to duplicate any more.
i would ideally like to duplicate the MC from the library. But that would mean putting the code to move everything in the main timeline or another MC which i'm trying to avoid.
----------------------
THE BOTTOM LINE
i need to duplicate the MC from the library which contains all the relevant code to move itself.
----------------------
any help/advice is good.
thanks.
_y Value In Movieclip Vs _y Value On Stage
When you refer to the _y value of a movieclip that is within another movieclip, does it refer to the _y position of the clip within the parentclip, or the _y postion of the clip in relation to the mainstage?
For example:
_root.bigbug.splat_y
splat's _y value within bigbug is at 0, but bigbug's _y value on the mainstage is 20.
Does this make _root.bigbug.splat_y=0 or _root.bigbug.splat_y=20
If you changed things to _parent.splat._y, would it change things as well?
Trying To Add A MovieClip To Stage...
I need some help cause i don't know why my movieclip doesn't appear on the stage. Here is the thing:
-> i create a class that's adding a movie clip to the stage ...and i only use this movieclip for once...when the user clicks on it it dissapears and then i instantiate another class and i try to add another MovieClip to the stage. .Here is the code for the second addChild:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class AlignMenu extends MovieClip
{
private var menu2:MenuR = new MenuR();
public function AlignMenu():void
{
trace("hello");
menu2.x = 100;
menu2.y = 105;
this.addChild(menu2);
trace(menu2);
menu2.btn1_resized.addEventListener(MouseEvent.CLI CK, onClick1);
menu2.btn2_resized.addEventListener(MouseEvent.CLI CK, onClick1);
menu2.btn3_resized.addEventListener(MouseEvent.CLI CK, onClick1);
menu2.btn4_resized.addEventListener(MouseEvent.CLI CK, onClick1);
menu2.btn5_resized.addEventListener(MouseEvent.CLI CK, onClick1);
menu2.btn6_resized.addEventListener(MouseEvent.CLI CK, onClick1);
}
private function onClick1(event:MouseEvent):void
{
trace("hello");
}
}
}
the problem is that i don't see the menu on the stage. I put a trace to see if the object is created and it is ... in the output window it shows me
----
hello
[object MenuR]
Somebody can give me a hint why can't i see the MovieClip on the stage ?
|