Possible To Clip Bounds Of Sprite/Movieclip?
Easy noob question for you: I'm using addChild() to add bitmaps to a 100x100 Sprite. I'm positioning these bitmaps with their x and y parameters. However, if the bitmap 'spills' over the edge of the 100x100 Sprite, I want it to be clipped. In other words, if I place a 50x50 image at the x,y coordinates of 90, 90, I only want the upper-left corner 10x10 pixels of the image to be shown. Does that make sense? How can I do this? Is there some 'clip' parameter?
Thanks in advance! -Rich
KirupaForum > Flash > ActionScript 3.0
Posted on: 03-25-2008, 09:42 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Clipping Bounds On Sprite/MovieClip
Easy noob question for you: I'm using addChild() to add bitmaps to a 100x100 Sprite. I'm positioning these bitmaps with their x and y parameters. However, if the bitmap 'spills' over the edge of the 100x100 Sprite, I want it to be clipped. In other words, if I place a 50x50 image at the x,y coordinates of 90, 90, I only want the upper-left corner 10x10 pixels of the image to be shown. Does that make sense? How can I do this? Is there some 'clip' parameter?
Thanks in advance!
-Rich
Finding The Bounds Of A Movieclip
Version: Flash CS3, AS3
Is there a way to find the bounds (width&height) of a single-frame movieclip in a way that disregards surrounding whitespace?
ie. if a movieclip contains only a 10x10 square at point 5,5 (within the movieclip), width&height is normally returned as 15x15. I want a way to have 10x10 returned.
Flash seems to know of such bounds - the graphic displayed in the library sidebar is set to this size. So are they accessible via AS3?
Thanks
Rick
Modifying The Bounds Of A Clip
I have a big movieclip but I just want to show a little peace of this movieclip. So I mask it with another movieclip with rectangles drawn in it and blendmode "alpha". The problem is that the rest of the clip (the masked part) is just then considered with _alpha=0; so actionscript always consider this clip as the whole big movieclip and it takes time to draw it on the screen.
So is it possible to really change (decrease) the bounds of a movieclip?
MovieClip Vs Sprite
What is the difference between MovieClip and Sprite? They seem to be used in the same way and are interchangeable. Is one a super class of the other?
2 example which seem to do the same thing
ActionScript Code:
import flash.display.Sprite;
import flash.events.MouseEvent;
var myClip:Sprite = new Sprite();
myClip.graphics.beginFill(0xff0000);
myClip.graphics.drawCircle(40, 40, 40);
addChild(myClip);
ActionScript Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
var myClip:MovieClip = new MovieClip();
myClip.graphics.beginFill(0xff0000);
myClip.graphics.drawCircle(40, 40, 40);
addChild(myClip);
Sprite Vs. Movieclip
Why, when and how should people extend the Sprite in a class vs. the MovieClip class?
Quote:
Originally Posted by adobe help file
The Sprite class is new in ActionScript 3.0. It provides an alternative to the functionality of the MovieClip class, which retains all the functionality of previous ActionScript releases to provide backward compatibility.
"backward compatibility in AS3" ?
MovieClip Or Sprite
Hello, I am an advanced user of AS2 and i am just getting into AS3. Can someone please explain the main differences between MovieClips and Sprites in AS3?
Thanks in advance
Q
Extends Movieclip/sprite Uses
Hello everyone i am new to oop knows by extending class we can access fields and methods of parent class but don't really know what ere the benefits of extending built in classes like
xmlParser extends XMLDocument;
clip extends Sprite
loader extends URLLoader;
and so on
thus anybody out there to help me thanks in advance
How Can I Know, Using As3, That An Object Is A Sprite Or A MovieClip?
Hi, I'm using a mouse event to check some UI. I was wondering if I can tell, from the "relatedObject" property of the event if the calling object is a MovieClip or a Sprite (for some functionality I want to include). The code is something like this:
private function console_barOut(event:MouseEvent):void {
trace (event.relatedObject.name); // returns the correct object name
// from here I would like to check "event.relatedObject.name" and take an action if it is a Sprite and another if it is a MovieClip
}
How Do I Convert A MovieClip To A Sprite?
Feeling a little overwelmed with the transistion from AS2 to AS3. I'm not a developer/coder, I wear the designer hat. I'm a graphics application instructor transitioning from AS2 to AS3 and I'm getting no where trying to figure out how to do a start and stop drag in the new version.
I have a simple exercise for my class that involves making movieclip symbols then using Startdrag & Stopdrag (or assigning via behaviors in Flash 8.0) to manipulate the movieclips in the player.
I need to be able to reproduce this in Action Script 3.0. I know it involves Sprites but I haven't been able to figure out how to set a Movieclip symbol as a Sprite.
Any assistance is greatly appreciated.
Shape, MovieClip Or Sprite?
Take a look at the code below:
ActionScript Code:
//var frame:Shape = new Shape();//var frame:Sprite = new Sprite();var frame:MovieClip = new MovieClip();frame.graphics.lineStyle(4, 0x333333, 1, true);frame.graphics.drawRoundRect(0, 0, 200, 200, 9);frame.graphics.endFill();frame.x = 50;frame.y = 50; addChild(frame);
This 'frame' can be created as a Shape, Sprite or MovieClip. In this case, are there any different between those? Better performance? In what case should I use this and in what case that?
MovieClip Frames To Sprite
Hi All,
I have a MovieClip that consists of 10 frames which are pages of a book.
I'd like to lay out the frames into the screen to see all of them.
Firstly, I thought that converting every frame to a sprite is a good idea but I couldn't make it.
Second, I tried to clone the MovieClip, but it also seems nightmare.
Do you have any idea?
Regards,
Viktor
How To Get Focus On A Movieclip Or Sprite
This starting to get very annoying so I had to seek some help.
How can I cause a sprite or movieclip to get focus on a Mouse Event? I realized that this only happens when I put a textfield inside the movieclip/sprite. If I click in an area outside the textfield (but still within the movieclip/sprite) it will cause the mouse event BUT it will not get focus -
My objective is to let the button once pressed, to cause the currently focused object to lose focus. That focused object is an input textfield.
Does it make sense what Im trying to achieve?
Bitmap Vs Movieclip/sprite
I wonder if any of you guys have some experience to share when it comes to render-speed using bitmapdata instead of movieclips/sprites using AS3?
I did some bitmap-test's in AS2, but I couldn't really notice any significant difference using bitmap vs movieclips.
Targeting Sprite As MovieClip(parent)
I have a MC1 with a comp.as class file
I have a MC2 with a object.as class file
- MC1 has all variables for the animation. It creates a number of MC2 children.
For some reason I can only use MovieClip(parent).somevariable in MC2 if I set the comp.as class file to package as "MovieClip" instead of "Sprite".
But that makes MC1 loop 2 frames nonstop.
Anybody knows how to call upon a Sprite as parent?
P
TransitionManager-Can You Get It To Accept Sprite Instead Of MovieClip?
Hello all,
I was trying out TransitionManager first time today and noticed it only worked with MovieClips. In my project, I have been using Sprites the entire time (I have also been using Tween instead of TransitionManager).
I am wondering if there is some way to get TransitionManager to accept Sprites.
I read that Sprites were more memory efficient than MovieClips, so that is why I want to use Sprite. However, I am not sure how significant this difference is. If anyone knows, please let me know. If the difference is not significant, I am not against using MovieClips. The most I am looking out of this is to pixelize a few images.
Thanks.
Shengzhi
Convert Sprite/MovieClip To Bitmap
I have a flash game, but it's too slow because there are to many instances on stage. So I got the idea that converting the Sprite/Movieclip containing the instances to a bitmap would speed it up.
Any Ideas?
Targeting Sprite As MovieClip(parent)
I have a MC1 with a comp.as class file
I have a MC2 with a object.as class file
- MC1 has all variables for the animation. It creates a number of MC2 children.
For some reason I can only use MovieClip(parent).somevariable in MC2 if I set the comp.as class file to package as "MovieClip" instead of "Sprite".
But that makes MC1 loop 2 frames nonstop.
Anybody knows how to call upon a Sprite as parent?
P
How To Unapply A Filter To An Movieclip, Sprite, Etc?
Hello all,
I've found a zillion articles how to apply a filter. I was happy I got that part. But how do you unapply it in Actionscript?
To test how to unapply a filter effect, I applied a glow effect myObject then added an EventListener to unapply it. That function has one line in it which is:
myObject.filters = [];
(since "myObject.filters = [myGlowEffect]" is the application of it, I thought by making it to nothing in the brackets would undo it.) But no, myObject does not cease to glow.
Anyone have an idea why this is so? Any help is appreciated.
Marion
Convert TextField To Sprite Or MovieClip
Hi there,
All I want to do is something like fading out some text. As this is not possible using a TextField I googled around for some hours but only found solutions where I had to use the Flash GUI ("Select the TextField, transform it into a symbol ...") and Ready-To-Use-Classes around 30$ - 150$
I tried stuff like that:
ActionScript Code:
var myText:TextField = new TextField;
var textSprite:Sprite = new Sprite;
myText.text = "Would someone fade me please?";
textSprite.addChild(myText);
addChild(textSprite);
textSprite.alpha = 0.5;
But it doesn't work. As there are commercial classes that solve such issues, there must be a way.
Hope you can help me
Please Help For Registration Point To A Movieclip/sprite
I am new to AS3 and have a doubt on Registration point for Movie clip / Sprite. Please help me the sample code for this
I simply draw a line using AS3 in flash environment. but i used graphics.moveTo for center. but if i run this it is simply taking x,y axis 0,0 and move around the stage. I want to move this from center of the stage. please help.
below is my code
var line:Sprite = new Sprite()
addChild(line);
var cx:Number = stage.stageWidth/2;
var cy:Number = stage.stageHeight/2;
var radius:Number = 1;
var increase:Number = 0;
line.graphics.lineStyle(1, 0xff00ff);
line.addEventListener(Event.ENTER_FRAME, onEnter);
function onEnter(event:Event):void
{
increase += radius;
//trace(increase);
//line.graphics.moveTo(cx, cy);
line.graphics.lineTo(cx + increase, cy + increase);
line.rotation += 0.1;
}
Sprite/Movieclip ButtonMode Question.
buttonMode is Sprite exclusive, correct? So is there any way to get a hand over my movieclips... Except by using a custom cursor?
I assume I can't place a movieclip inside a sprite. And this... I don't think this will work...
var newButton:Sprite = new menuButton();
newButton.buttonMode = true;
Accessing A MovieClip Inside Of A Sprite?
I have a game where the user can drag objects around. However, these objects need to be clamped to certain areas, and are unable to move past other moveable objects.
To achieve this clamping, I have placed a 25x25 pixel movieclip inside my sprite. In my actionscript, I am then attempting to call this movieclip so I can see if it is in the way of anything. However, despite my best efforts, I have been unable to get ActionScript to even see that this collision MovieClip exists.
I'm using the following code currently to check for the existence of the clip:
trace(MovieClip(player.parent).playerCollision);
This, however, always returns 'null'. I'm at a bit of a loss... any help would be great!
Thanks,
-BZ
Saving MovieClip/Sprite As Image
Hello.
I'm building an application that allows you to drag images from a catalog into a blank area, move/rotate/scale them, etc. This blank area is a display object and the images are added as its children.
I'd like to know if it's possible to save the display object, or all of the Stage, if need be, as an image.
Thank you. http://www.vivoeusebio.com
Code To Change The Depth Of A Sprite/Movieclip?
Hey,
Is there actionscript code to change the depth of a sprite on the stage?
I'm currently working on a small little project where I have 4 circles rotating around. When objectB hits objectA I want objectB to appear in front so I want that to change depths to the highest depth. Then later on in the animation I want objectC to appear in front of objectB and so on. Creating a 3d illusion of the 2d sprite rotating around.
Any examples too would be excellent.
Cheers!
Loader And Using Hand Cursor (Get Sprite Or MovieClip Our Of It)
Good morning everyone, I am having an issue over here. I have a loader that ... loads an image, but I can't get it to show the hand cursor (since the image is a link so to speak). With a label I can do a label.buttonMode = true; label.useHandCursor = true; since Label class is a son of Sprite or grandson or whatever, but loader isnt :S So I wonder, is there any way to get a Sprite or MovieClip out of a Loader object? Thanks for your time!
Sprite Or Movie Clip ?
Hi, I've read that it is more efficient in AS3 to use sprites than movie clips when I don't need timeline. I want to use only AS3 for moving graphics, not timeline, so it would be good to create sprite objects. But is there a way to load vector graphic made in Flash to it?
I mean, to use Flash CS3 graphical editor to draw something, then use AS3 to move it. If there was a possibility to create some drawing in Flash, then save it to library as symbol, then load it in AS3 to a sprite (like I can load a bitmap). But only "Movie Clip" symbol instances can have names, not "Graphic" instances, so it looks that the only way is to create a Movie Clip in Flash.
It means that if I want to draw in Flash and not in AS3, I must use Movie Clips?
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.
Dynamicly Created Movieclip/sprite And .width Property
I have a question on WHEN you can read the width of a dynamically created sprite.
I have a gallery package - the gallery.as file creates a thumbContainer (MovieClip) and adds each thumbnail (sprite) in a for loop, iterating through an array.
Within the for loop, i try to trace the width of the thumbContainer, but it always returns 0. What gives? I need the final width to make some calculations for the scrolling of the thumbnails to work.
I can get the final width using certain methods, such as returning the width on MOUSE_MOVE. I was able to get the width using the eventListener Event.ADDED, but that stopped working when loading images off my server instead of locally (wtf is that about?).
Can anyone give some clarification on dynamically created containers and their properties (specifically reading their width property) ?
Problem With MouseEvents Of Items Inside Sprite/MovieClip
Hi,
i try to build a simple navigation bar using a sprite with buttons (sprites with textfields) inside. The menu is initially hidden and should slide
down if it recieves a MOUSE_OVER event. No Problem so far, i add an EventListener for MOUSE_OVER and MOUSE_OUT so it slides up if mouse
leaves the menu.
I want the buttons to change color if the mouse hovers so i add them a MOUSE_OVER and MOUSE_OUT.
But now, if the mouse is over the button the menu receivs a MOUSE_OUT because the mouse is now over the button and no longer over the menu.
How can i provent sending an MOUSE_OUT event from the menu if the mouse enters the button? If i set mouseChildren = true for the menu the
buttons don't receive any events so that would'nt help.
Anyone got an idea how this could be done?
Create a new Flash CS3 AS3 File, insert the code in frame 1. Watch the trace output if you move over the button on top to see what i mean.
Code:
// create menu bar
var menu:Sprite = new Sprite();
menu.graphics.beginFill(0xcccccc);
menu.graphics.drawRect(0, 0, stage.stageWidth, 100);
menu.graphics.endFill();
// create clickable link inside that menu bar
var spText:Sprite = new Sprite();
var tfText:TextField = new TextField();
tfText.autoSize = TextFieldAutoSize.LEFT;
tfText.textColor = 0x000000;
tfText.text = 'click me';
var bounds:Rectangle = tfText.getBounds(this);
// position everything
spText.x = 10;
spText.y = 70;
menu.y = -90;
spText.addChild(tfText);
menu.addChild(spText);
spText.buttonMode = true;
spText.mouseChildren = false;
addChild(menu);
// add event listener
menu.addEventListener(MouseEvent.MOUSE_OVER, expandMenuBar);
menu.addEventListener(MouseEvent.MOUSE_OUT, collapseMenuBar);
function expandMenuBar(e:MouseEvent):void {
trace('exand menu bar');
menu.y = 0;
}
function collapseMenuBar(e:MouseEvent):void {
trace('collapse menu bar');
menu.y = -90;
}
spText.addEventListener(MouseEvent.MOUSE_OVER, highlightLink);
spText.addEventListener(MouseEvent.MOUSE_OUT, unHighlightLink);
function highlightLink(e:MouseEvent):void {
tfText.textColor = 0xff0000;
}
function unHighlightLink(e:MouseEvent):void {
tfText.textColor = 0x000000;
}
A Simple Question On Sprite Or Movie Clip For Center
I simply draw a line using AS3 in flash environment. but i used moveTo for center. but if i run this it is simply taking x,y axis 0,0 and move around. I want to move this from center of the stage. please help.
below is my code
var line:Sprite = new Sprite()
addChild(line);
var cx:Number = stage.stageWidth/2;
var cy:Number = stage.stageHeight/2;
var radius:Number = 1;
var increase:Number = 0;
line.graphics.lineStyle(1, 0xff00ff);
line.addEventListener(Event.ENTER_FRAME, onEnter);
function onEnter(event:Event):void
{
increase += radius;
//trace(increase);
//line.graphics.moveTo(cx, cy);
line.graphics.lineTo(cx + increase, cy + increase);
line.rotation += 0.1;
}
Loading Sprite Using Loader Need Access To Sprite Type
Hello,
I'm loading a Sprite via a Loader and once loaded I have access to that Sprite via the Loader class. I can manipulate the Sprites alpha, x and y coordinates ect. However, I have a custom function that fades in or out the passed param and it expects a Sprite. When I pass the loaded Sprite (loaded via the Loader class) I get an error:
1067: Implicit coercion of a value of type flash.display:Loader to an unrelated type flash.display:Sprite.
I know that the problem is that it expects a Sprite, but how do I access the Sprite type once the swf is loaded via the Loader?
My Code:
import FadeClip;
var ldrMovieCntr:Loader = new Loader();
addChild(ldrMovieCntr);
var fcLoadedMovie:FadeClip = new FadeClip(); //CUSTOM CLASS
fcLoadedMovie.setClipToFade(ldrMovieCntr); //PASSING IN A TYPE Loader - CLASS EXPECTS A Sprite
Thanks in advanced,
Vic
HELP: Sprite.addChild(NumericStepper) Resizes Sprite To 100x100
If anyone can help me with this, I would be extremely grateful. It's driving me insane.
If I run this code:
Quote:
var mySprite:Sprite = new Sprite();
trace("mySprite 1:", mySprite.width, mySprite.height);
numericStepper = new NumericStepper();
trace("numericStepper 2:", numericStepper.width, numericStepper.height);
mySprite.addChild(numericStepper);
trace("mySprite 3:", mySprite.width, mySprite.height);
I expect this output:
Quote:
mySprite 1: 0 0
numericStepper 2: 80 22
mySprite 3: 80 22
But I get this output:
Quote:
mySprite 1: 0 0
numericStepper 2: 80 22
mySprite 3: 100 100
If instead I do this:
Quote:
mySprite = new Sprite();
trace("mySprite 1:", mySprite.width, mySprite.height);
numericStepper = new NumericStepper();
trace("numericStepper 2:", numericStepper.width, numericStepper.height);
mySprite.addChild(numericStepper);
trace("mySprite 3:", mySprite.width, mySprite.height);
mySprite.width = 80;
mySprite.height = 22;
Then the numericStepper is drawn as if it is squished to 20% its normal height.
If I pre-set mySprite width and height before adding the numericstepper, the trace output is 0,0 after adding it and it is not displayed at all.
Is there some way I can make the sprite only adjust to correctly fit the numericStepper OR resize it afterwards without distorting the numericStepper component?
As I was typing this, I came across this post:
http://www.kirupa.com/forum/archive/.../t-263027.html
Can anyone help me modify that solution for a numeric stepper?
Thanks!
Dynamically Creating Sprite Inside Sprite
I'm having issues going from AS2 to AS3, mainly in this part , creating sprites/movieclips inside other sprites/movieclips, back in the days i could just create an emptymovieclip inside another, and easily locate it (fathermc.childmc), now the issue is i cant really locate the child, and from the research i have been doing i think i cannot have multiple child with the same name.
I need this because i usually work with textfields inside movieclips, and at any given time i will need to change the text on a specific movieclip's textfield, and i'm having some trouble with that for now.
Here is an example code
Code:
import flash.display.Sprite;
import flash.events.MouseEvent;
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFFCC00);
circle1.graphics.drawCircle(0, 0, 40);
var circle3:Sprite = new Sprite();
circle3.graphics.beginFill(0xFF0000);
circle3.graphics.drawCircle(0, 0, 200);
circle3.alpha = 0.5;
function BuildInside(spr:Sprite) {
var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0xFFCCC0);
circle2.graphics.drawCircle(0, 0, 60);
circle2.alpha = 0.5;
spr.addChild(circle2);
}
addChild(circle1);
addChild(circle3);
BuildInside(circle1);
BuildInside(circle3);
circle1.x = 530;
circle3.x = 230;
//trace(circle1.x + " OK " + circle1.x);
stop();
i know that putting
Code:
var circle2:Sprite = new Sprite();
, inside a function , it will only be available in that function , but how can i make it available globally, do i need to define all of them in advance at the root ?
in this example i cant reach any of the circle2 inside the other circles, probly because of the var defining inside the function again.
thnx in advance for any help in this issue that has been holding back my AS2-AS3 upgrade
Why Does Sprite.filter Break Sprite.hitArea ?
Check this weird bug:
By adding the dropshadow to the circle, hit area no longer works. If you comment them out they work fine. WTHeck?
Code:
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(0, 0, 40);
var dShadow:DropShadowFilter = new DropShadowFilter();
circle.filters = [dShadow];
var square:Sprite = new Sprite();
square.graphics.beginFill(0xCCFF00);
square.graphics.drawRect(200, 0, 100, 100);
circle.hitArea = square;
square.mouseEnabled = false;
circle.addEventListener(MouseEvent.CLICK, clicked);
function clicked(event:MouseEvent):void{
trace(event.target == circle); // true
trace(event.target == square); // false
}
addChild(circle);
addChild(square);
Sprite And Child Sprite, Click Event On Both
Hello.
I have this menu item, which is a Sprite. The menu item then has several other items, also Sprite, as children. All items have a listener for click events. When I click the parent item, it's all ok, but when I click one of the children, both the child and the parent Sprite's event handler functions are triggered.
How can I stop the parent sprite from responding to the click on the child?
Thanks in advance.
Attach Code
var myParent:Sprite = new Sprite();
var myChild1:Sprite = new Sprite();
myParent.addChild(myChild1);
function click_parent ($event:MouseEvent) {
trace ("parent clicked");
}
function click_child ($event:MouseEvent) {
trace ("child clicked");
}
myParent.addEventListener(MouseEvent.CLICK, click_parent);
myChild.addEventListener(MouseEvent.CLICK, click_child);
//(Clicking myParent)
//parent clicked
//(Clicking myChild1)
//child clicked
//parent clicked
Add Listener When Sprite Hovers Over Sprite
Hi guys,
This is my first time looking for help on these forums so im giving it a go.
I have been trying to find the answer for this for a while with no luck
I have a grid with cells
When i hover over with a mouse it changes the color if the cell .... thats ok
What i want to do is hover over a cell with another object sprite and ofr it also to change color
Is their an event for this or does anyone have suggestions for another option
Thanks for any suggestions.
What i am thing is to substitute MouseEvent.ROLL_OVER for something else that will trigger when an object hovers over.
Some code:
Code:
public function createCell()
{
var temp_cell_object:Sprite = new Sprite();
........
.......
.......
the_cell_object.addEventListener(MouseEvent.ROLL_OVER,setCellBackgroundHighlightOn);
the_cell_object.addEventListener(MouseEvent.ROLL_OUT,setCellBackgroundHighlightOff);
the_cell_object.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
return temp_cell_object;
}
private function setCellBackgroundHighlightOn(evt:MouseEvent)
{
evt.target.transform.colorTransform = new ColorTransform(1, 1, .25, 1, 40, 0, 25, 0);
}
private function setCellBackgroundHighlightOff(evt:MouseEvent)
{
evt.target.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
}
[CS3] Sprite Collision/gravity Within Another Sprite
I'm doin an assignment based on flash but I jus learnt basic flash bt my assignment has forcen me to script higher than the level tat i had learnt.
This is roughly my idea:
correction: instead of e edge change color when the ball collide it, the ball will change color when it collide with the edges. I'm realli grateful to those who can teach & help me~ My assignment is due in 2 days time on thurs.. Thank you~
Sprite Collision/gravity Within Another Sprite
I'm doin an assignment based on flash but I jus learnt basic flash bt my assignment has forcen me to script higher than the level tat i had learnt.
This is roughly my idea:
correction: instead of e edge change color when the ball collide it, the ball will change color when it collide with the edges. I'm realli grateful to those who can teach & help me~ My assignment is due in 2 days time on thurs.. Thank you~
Cannot AddChilld(sprite) Into Another Sprite?
Hi,
First post woo,
Anyways, I'm quite new to AS3, I worked a bit with AS2 but not to a great extent, and I am now trying to teach myself AS3 (with a little help). I am creating a flash portfolio and so far have got images to import via XML and some other things, but I am stuck at one particular point:
I have an AS file called Statics.as that extends Sprite, it will contain all the code to draw the static elements of the portfolio, so far it draws a rounded rectange with gradient fine.
I then used URLRequest() and URLLoader() to load the XML, and then Loader to load the logo of the portfolio. I can add it to the Sprite now with:
Code:
addChild(logoLoader);
But I want to manipulate the x and y coords first. I initially failed as I tried to position it in the top right of the portfolio using:
Code:
logoLoader.x = 720-logoLoader.width -10
(720 being the width of the portfolio, and 10 being the padding from the right)
This did not work, after tracing logoLoader.width it seems that this property is not given and so tells me the width of the logo is 0. Therefore the x coord of the logo was mostly off the screen.
I then tried putting the logo into its own sprite to manipulate using:
Code:
var logoSprite:Sprite = new Sprite;
logoSprite.addChild(logoLoader);
logoSprite.addEventListener(Event.ADDED,logoComplete);
This didn't throw any errors, so I continued with:
Code:
public function logoComplete(evnt:Event)
{
evnt.target.x = 720-evnt.target.width -10;
trace(evnt.target.x);
}
This gave me an x coord value of 382 which is correct, this would position the logo in the top right hand corner in exactly the place I wanted.
But when I tried adding it as a child to the class, I got an error:
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display: DisplayObject.
I believe the problem is that I am trying to add a Sprite as a child into a Sprite. As AS3 is quite new to me, I don't see why this should be a problem or a way around it, so my question is; Is what I am doing, the right way of manipulating the position of an external image before it being added to the stage?
Thankyou for your time,
Any reply is appreciated,
Blekk.
P.S.
A new instance of the AS file Statics.as is added to the stage via the DocumentClass.
Here is all the code relevant to the problem if needed:
Code:
package com.fusedDesign.userinterface
{
import flash.display.*;
import flash.geom.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class Statics extends MovieClip
{
public function Statics()
{
drawModule();
drawLogo();
}
public function drawLogo()
{
var urlRequest:URLRequest = new URLRequest("com/fusedDesign/folio/xml.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.load(urlRequest);
urlLoader.addEventListener(Event.COMPLETE,xmlComplete);
}
public function xmlComplete(evnt:Event)
{
var imagesXML:XML = new XML(evnt.target.data);
loadImage(imagesXML);
}
public function loadImage(xml:XML)
{
var logoLoader:Loader = new Loader();
var logoRequest:URLRequest = new URLRequest(xml.logo.attribute("href")[0]);
logoLoader.load(logoRequest);
var logo:Sprite = new Sprite();
logo.addChild(logoLoader);
logo.addEventListener(Event.ADDED,logoLoaded);
}
public function logoLoaded(evnt:Event)
{
trace("added");
evnt.target.x = 720-evnt.target.width-10;
evnt.target.y = 10;
addChild(evnt.target);
}
}
}
I have removed the code that draws and adds the rounded rectangle.
Store A Sprite In A Sprite?
What is the best thing to do when storing a Sprite to call it later?
- save it to an array ("as Sprite") (I only need to store one value!)?
- save the name as String in a string variable then getChildByName?
- save it in a variable type Sprite?
three ways seam to work fine, really don't know if there is another one, neither which one is more correct.
any ideias?
thanks
Get Bounds
hey pplz, is get bounds used for games????
coz i want to know how to make it so that when my character moves over a hill he will go over the hill and walk up a little, if u know wot i mean.
also , this has no relation lol , how duz Xiao Xiao make it so that when u push that button, it slows the frame rate and it goes in slow motion ( XIAO XIAO 3 )
thanx pplz
Skribble
_______________________________
www.skribblinteractive.tk
Out Of Bounds?
Hello... If a user drags a piece off the screen my program goes crazy.
www.enjoychess.com. Grab a piece and take it all the way to the edge of the screen and you will see what I mean.
I have event handlers and boundaries set and they work, but when the user takes the piece all the way to edge it goes nuts.
Any idea? Thanks!!
I am using flash mx 2004 pro
ANDY
Bounds
Hello,
I have a big problem in my game. I can not make bounds! In a way I can but not in this case. The problem that it's the background that is moving, not the car. So I would really appreciate if someone could explain me how to do it.
Thanks.
Here is the script I put on the background (the car is called "bil") :
onClipEvent (load) {
speed = 8;
}
onClipEvent (enterFrame) {
if (key.isdown(key.LEFT)) {
_x += speed;
}
if (key.isdown(key.RIGHT)) {
_x -= speed;
}
if (key.isdown(key.DOWN)) {
_y -= speed;
}
if (key.isdown(key.UP)) {
_y += speed;
}
}
onClipEvent (enterFrame) {
if (_root.bil.hitTest(_root.Wall4) or _root.bil.hitTest(_root.wall5) or _root.bil.hitTest(_root.wall6) or _root.bil.hitTest(_root.wall7) or _root.bil.hitTest(_root.wall8) or _root.bil.hitTest(_root.wall9) or _root.bil.hitTest(_root.wall10) or _root.bil.hitTest(_root.wall11) or _root.bil.hitTest(_root.wall12)) {
speed = 0.1;
} else {
speed = 8;
}
}
And this one on the car :
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_rotation = 90;
}
if (Key.isDown(Key.LEFT)) {
_rotation = 270;
}
if (Key.isDown(Key.UP)) {
_rotation = 0;
}
if (Key.isDown(Key.DOWN)) {
_rotation = 180;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
_rotation = 45;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
_rotation = 315;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
_rotation = 135;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
_rotation = 225;
}
}
Scrolling Bounds >?
hey ,
i have a mc called pic ,i am tring to have it appear at the _x pos when it scrolls out of the 300 width area to start over again ..
here is what i have for the arrow keys ..
*********i didnt add any of the code examples for the _x pos ..but the stage is 300x50
Code:
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == 37) {
picture._x -= 2;
}
};
Key.addListener(myListener);
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == 39) {
picture._x += 2;
}
};
Key.addListener(myListener);
cheers ..
Bounds For DraGging
Does anyone know how to create bounderies for a dragable object, so when the side of it gets to the bounderies it stops moving on either the X or Y axis depending on where ti hits?
thanks in advance
-Stwelin
|