How To Duplicate An Displayable Object?
HI are there any other possible ways to duplicate a displayable objects like Sprites for example?I'm using that approach:var GetInstance:Class = targetDisplayableObject["constructor"];var copyOfTargetDisplayableObject:Sprite = new GetInstance();ThanksmloncaricEdited: 06/28/2007 at 03:56:42 AM by mloncaric
Adobe > ActionScript 1 and 2
Posted on: 06/28/2007 03:32:20 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Duplicate Object Adjacent To The First Object
Hi guys,
I am creating duplicate on clicking a buton but it is puting the duplicate on the same place but i wanna put duplicate object adjacent to the first object , whether it's having any angle or straight.
Actionscript:
function dupMovie(targetitem, basewidth, baseheight, baserotation, x_base, y_base) {
itemcount += 1;
duplicateMovieClip(targetitem, ("item" + itemcount), (16384 + (itemcount + 2000)));
item += itemcount;
setProperty(("item" + itemcount), _x, x_base);
setProperty(("item" + itemcount), _y, y_base);
setProperty(("item" + itemcount), _width, basewidth);
setProperty(("item" + itemcount), _height, baseheight);
setProperty(("item" + itemcount), _rotation, baserotation);
itemWidth = basewidth;
itemHeight = baseheight;
itemRotation = baserotation;
}
I am geting width and height of every object but with every dragable item i wanna attach a text box having widht.
for reference download movie.
http://www.geocities.com/rajmultimedia/movie.fla
regards
raj
Duplicate Object
I know this sounds silly... but how do you define your duplicate preferences in Flash 5... I mean, if you want to duplicate a line exactly 5 pixels under the the one before it? By default it appears lower and to right hand side - surely there must be some dialogue box where you can define the Duplicate parameters? - I feel embarrassed I cannot find it.
Duplicate Object
Hi all,
I have been working on an animation where an object is supposed to vibrate and rotate on itself within a specific area of my stage. I have been successful in having the object vibrate, rotate and start at the specified location. What I am having trouble with, is creating about 60 instances of the same object to move in the area I specified. All I get instead, is the one object to vibrate about and rotate. I am using AS2 and the following is the code I have attached to the "particle_mc".
onClipEvent (enterFrame) {
this._rotation = (this._rotation + (3))%360;
}
onClipEvent (enterFrame) {
width = 330; // area where animation should be segregated into
height = 380;
this._x = 577 //Math.round(Math.random()*width);
this._y = 347; //Math.round(Math.random()*height);
cx = this._x;
cy = this._y;
}
onClipEvent (enterFrame) {
this._x = cx+(Math.random()*7);
this._y = cy+(Math.random()*7);
}
Also in Frame 1 I put this code
i = 0;
while (i<60) {
//duplicateMovieClip("particle_mc"+i, i);
particle_mc.duplicateMovieClip("particle_mc"+i, i);
i++;
}
hoping to get multiple instances of the object, but no success!
Any HELP would be greatly appreciated
Brutium
Duplicate Object
Help!!!! I am using Flash mx 2004 and I am trying to get the duplicate object command to work. I have created a movie clip called 'box' and when you click a button, I would like it to create a duplicate. This is the code I am using:
on(release){
duplicateMovieClip(box, box2, 1);
box2._x = 100
box2._y = 100
}
Flash cannot find an error in the code, but when i try it, nothing happens! What is wrong with this code?
HELP Duplicate Object
Hi all,
I have been working on an animation where an object is supposed to vibrate and rotate on itself within a specific area of my stage. I have been successful in having the object vibrate, rotate and start at the specified location. What I am having trouble with, is creating about 60 instances of the same object to move in the area I specified. All I get instead, is the one object to vibrate about and rotate. I am using AS2 and the following is the code I have attached to the "particle_mc".
onClipEvent (enterFrame) {
this._rotation = (this._rotation + (3))%360;
}
onClipEvent (enterFrame) {
width = 330; // area where animation should be segregated into
height = 380;
this._x = 577 //Math.round(Math.random()*width);
this._y = 347; //Math.round(Math.random()*height);
cx = this._x;
cy = this._y;
}
onClipEvent (enterFrame) {
this._x = cx+(Math.random()*7);
this._y = cy+(Math.random()*7);
}
Also in Frame 1 I put this code
i = 0;
while (i<60) {
//duplicateMovieClip("particle_mc"+i, i);
particle_mc.duplicateMovieClip("particle_mc"+i, i);
i++;
}
hoping to get multiple instances of the object, but no success!
Any HELP would be greatly appreciated
Brutium
Duplicate (movieclip/object)
hi friends,
i am new in action scripting. you can say that i dont know action scripting at all. but i want to learn. as i started flash, i got that action scripting is more diffrent than i thought. but a little hope from normal user and expert mode. here i want to ask one thing that from where can i get properties of all actions in action script. like duplicatemovieclip. how can i use this?. is this possible that we duplicate objectes? and is it possible that we duplicate movieclip after a specific time in loop? i mean as we can settimeout property in javascript. plz send me the code
How To Duplicate Object Movement?
well I have this frame as a movieclip called field. And inside it, there's another mc that is moved by the cursor keys called box. Now I have created another movie clip called boxclone. I want boxclone to make the same movement as the box in the field. I know it has something to do with localToGlobal but I don't know how to setup the code correctly...
[F8] How To Duplicate An Object Instance...
So I created an object and gave it a few default properties. Now I want to be able to duplicate that object when a new movieclip is created.
My problem is that if I do something like, var newObject:Object = oldObject; then when I change a property in one, it also changes the other. So it's not actually creating a new instance of the old object, but reflecting it.
Does anyone know how to duplicate an object?
Code:
var oldObject:Object = new Object();
oldObject.name = "ONE";
var newObject:Object = new Object(oldObject);
trace(oldObject.name+" - "+newObject.name);
// outputs "ONE - ONE"
newObject.name = "TWO";
trace(oldObject.name+" - "+newObject.name);
// outputs "TWO - TWO"
Duplicate Object And Drag It.
Hello, im new to the forum and relative new to actionscript but im learning more and more as the days go.
What i would like to know is how do i make a duplicated or attached object dragable?
What i want is, i push a button and it will place a MC on the scen and then i want to be able to drag and drop that MC.
How To Duplicate Object Movement?
well I have this frame as a movieclip called field. And inside it, there's another mc that is moved by the cursor keys called box. Now I have created another movie clip called boxclone. I want boxclone to make the same movement as the box in the field. I know it has something to do with localToGlobal but I don't know how to setup the code correctly...
Create Duplicate Of Object
I have an object that I have created with "foo = new Object()". I would like to create a duplicate of this object, but it seems every way I try, the duplicate is actually just a reference to the same original object.
For example:
[code]foo = new Object();
foo.member = 3;
bar = foo;
bar.member = 5;
trace(bar.member); // It outputs 5, of course
trace(foo.member); // It outputs 5 also ?!?!?
Of course that's a trivial case. But I need to duplicate the object so that the new object is completely separate from the original. Is it even possible?
All help is appreciated.
RecordSet Object & Duplicate Movie
Hi All,
I'm looking for an example on how to effectively use the duplicate movie and the Flash RecordSet object together.
My project involves duplicating some movie clips with values that are being populated by some coldfusion queries resulting in lists of values. We pass those to Flash, then loop the values into arrays and assign values to the movie clips based on position in the array.
piece-o-the-ColdFusion:
<CFSET STNNUM_LIST="">
<CFSET STNNUM_SUB_LIST="">
<CFSET STNID_LIST="">
<CFSET STNNUM_LIST=ListAppend(STNNUM_LIST,QE2.STNNUM,"|") >
<CFSET STNtype_LIST=ListAppend(STNtype_LIST,QE2.STNITMCOD ,"|")>
<CFSET LOCATION_LIST=ListAppend(LOCATION_LIST,QE2.STNLOCD SC,"|")>
piece-o-the-ActionScript:
// convert CF variables to Flash arrays
stnnum = stnnum.split("|");
stnnum_sub = stnnum_sub.split("|");
stnid = stnid.split("|");
slgstnid = slgstnid.split("|");
then later to assign the properties and dupe the clip:
for (k=0; k<(stnnum.length); k++) {
// this assures that coords are of a number value
xCoord[k] = Number(xCoord[k]);
yCoord[k] = Number(yCoord[k]);
// clone movie clip and name it
rClip = mcMaster.duplicateMovieClip("mc"+k, k);
// set position
rClip._y = initialy + (buttonheight * k);
rClip._x = initialx + (buttonheight * k);
rClip.tgtdsc = tgtdsc[k];
}
stop();
The big key for me has traditionally been, for example, that the 4th item in all of the arrays described the info for the 4th movieclip.
The method seems to be working well, but I'm a little unsettled about passing so many values through a string value...
I'm looking for a method to be able to extract usable variables from a recordset object to avoid having to use the loadVars approach. I get a great looking return from the NetConnection Debugger that confirms that I'm connected and returning propely. I get...
Result (object #2)
.....mRecordsAvailable: 3
.....serverinfo: (undefined)
.....uniqueID: 3
.....items (object #3)
..........[0] (object #4)
...............Activity: "Yes"
...............CUSNUM: 8699
...............PRYSID: 5
...............PTYID: 8333
...............RecentCount: 8
...............STNUM: 205
...............STNUM_SUB: "A"
...............StationItem: "Monitoring Regluar SVC"
...............StationType: "MON"
...............Status: "ACT"
...............WBHSTNID: 3
...............__ID__: 0
...............LastInspected (object #5)
...................."Sun May 4 00:00:00 GMT-0400 2003"
..........[1] (object #6)
...............Activity: "Yes"
...............CUSNUM: 8699
...............PRYSID: 5
...............PTYID: 8333
...............RecentCount: 3
...............STNUM: 100
...............STNUM_SUB: (undefined)
...............StationItem: "Monitoring Regluar SVC"
...............StationType: "MON"
...............Status: "ACT"
...............WBHSTNID: 1
...............__ID__: 1
...............LastInspected (object #7)
...................."Fri May 2 00:00:00 GMT-0400 2003"
..........[2] (object #8)
...............Activity: "Yes"
...............CUSNUM: 8699
...............PRYSID: 5
...............PTYID: 8333
...............RecentCount: 6
...............STNUM: 205
...............STNUM_SUB: (undefined)
...............StationItem: "Monitoring Regluar SVC"
...............StationType: "MON"
...............Status: "ACT"
...............WBHSTNID: 2
...............__ID__: 2
...............LastInspected (object #9)
...................."Sat May 3 00:00:00 GMT-0400 2003"
.....mTitles (object #10)
..........[0]: "WBHSTNID"
..........[1]: "StationType"
..........[10]: "STNUM"
..........[11]: "STNUM_SUB"
..........[2]: "StationItem"
..........[3]: "Activity"
..........[4]: "LastInspected"
..........[5]: "RecentTargetCount"
..........[6]: "Status"
..........[7]: "CUSNUM"
..........[8]: "PTYID"
..........[9]: "PRYSID"
.....views (object #11)
..........No properties
Which (though for the moment lacking positional x, y data) has all of the other attributes that I am trying to assign to my duplicated clips (aside from the inspected date which looks screwy to me)...
I've found that in flash I can use a couple of the recordset instructions that give me some summary info about the recordset:
//list of column names
rs.getColumnNames().join();
//The total number of records in the RecordSet
recordcount = rs.getLength();
But I'm feeling cornered by Recordsets otherwise. It seems great for presenting datagrids, but that's not really what I'm after. I need to use the values in that recordset to affect the appearance and elements of my movie...
I'm sure I'm just missing the boat here, anybody got an example or a method I can try here?
thanks,
Steve
Duplicate Movie Clip & Init Object
Hi all,
Has the duplicateMovieClip function been changed. a call such as
PHP Code:
for(i=0; i<=20; i++)
{
this.duplicateMovieClip("box"+i, i);
_parent["box"+i]._x = random(20);
}
This type of code used to work in duplicating movie clips. is the object declaration required with this call in flash mx 2004?
Duplicate Object Disappearing(simple Code)
i click to duplicate and i see it apear for a quarter second then it disappears.
what am i doing wrong?
Code:
onClipEvent (enterFrame) {
//make sure that duplicates dont move
if(this._name="Blue"){
this._x = _root.cur_x;
}}
onClipEvent (mouseDown) {
//duplicates blue and makes blue2
this.duplicateMovieClip("Blue2",1);
//puts blue2 at _x 50
_root.Blue2._x=50;
}
=Flash mx=
How/may I Duplicate Or Clone The Contents Of A Loader Object?
I want to load some .swf files using the Loader class. I'm all set with that and got the image on screen but I wish to have multiple instances of it. Do I have to reload one for each that I intent on using?
For example say I'm attempting to load a power up's graphic from an .swf (i'll call it ex.swf). I load it and then put the image I loaded into the power up. But then I also want to have another power up of the same type somewhere else, and I want to use that same graphic. Neither adding the loaded ex.swf's contents or simply assigning the contents to a child of the power up will work obviously. So do I have to load a new copy every single time i want a new one, or can I just clone/duplicate the contents?
Elsewise, is there another way I should be doing this? I mean I know it must be common for games to have 100's of copies of the same graphic being used by different things, yet If I try to preload the amount I'd need it's not exactly flexibly and if I load them as I need them it seems bad practice.. i dunno, let me know what you guys do,
Thanks,
Bobby
Array In Object Doesn't Duplicate Upon Instantiating
I guess I'm victim of my own misunderstanding of OOP but can somebody tell me why if I create two instances of an object which itself creates another array object, I end up referencing the same array ?
I've attached some oversimplified code to make things clearer. Why are both arrays containing the same data ? Aren't they different objects ?
Attach Code
class test
{
public var index:Array = new Array();
public function add(someValue:String):Void
{
this.index.push(someValue);
}
}
And then, here is the code in my .fla file
myTest1 = new test();
myTest1.add('abc');
myTest2 = new test();
myTest2.add('def');
trace(myTest1.index);
trace(myTest2.index);
The result I get is:
abc,def
abc,def
I was expecting:
abc
def
Duplicate Image Loaded Into Loader Object
I realize that I have to use the Loader object to load an external image. The problem I am having with the loader Object is that it doesn't support the addChild methods. Please correct me if I'm wrong. An example.
var sprite:Sprite = new Square(); //imagine a square class that draws a Square
var loader:Loader = new Loader("pic.jpg");
loader.addChild(sprite); //gives an error
//supposedly because the Loader object can only have one child which is pic.jpg
I am in a situation where I want to duplicate the picture that I have loaded into the Loader object, so I can have two instances on the stage doing different things. How would I do that?
also, I've tried doing something like this:
var loader2:Loader = new Loader();
loader2 = loader; //also give an error, because the loader get's something from a URL
Hopefully that's enough info to go on. THANKS!
Duplicate Movieclip, Drag Duplicate, Leave Original Behind
Hello all,
I have been searching frantically for an answer to this. I know it has to be easy....
I want to duplicate a movieclip on press and also drag the duplicate, leaving the original behind. I've attached a sample of what I'm doing. Does anyone have any ideas? Is there a way to target the duplicated movieclip to drag that? And leave the original in it's original location?
Any help, guidance, nudging would be greatly appreciated. I've been trying to figure this out for hours.
Thanks,
jessicuh
"Duplicate Scene" Does NOT Duplicate
I just erased a month's worth of work because Macromedia has a funny definition for "duplicate."
I have different scenes which will make up my movie. I build one. it has certain characteristics I want the other scenes to include. So I duplicate the first one, rename it, then make my changes. Straightforward, right? Only, duplicate actually seems to duplicate and link or attach the original and the copy. It does not make a copy, a separate and distinct scene!!!! SO I go back to my first scene, and everything is gone, because it's mysteriously linked or a clone or something of the one I just created (the copy). It's like you have two instances of the scene, and editing either one affects the other. It wasn't so in F5.
What the #$@$*%?!!
Can anyone explain?
Making An Object Dissapear Once A Moving Object Makes Contact With It
Hello there,
Im in need of some help. Basically I need a code which will make an object disappear once another moving object hits it (MovieClips controlled by AS)
For example, a bullet comes out of the gun and hits a can which makes the can disappear as soon as the bullet hits it.
Is it something to do with the "intersects" function? I've been trying to solve it all day and cant do it
Please help.
Whats It Called When You Drag An Object And Want The Object To Continue Moving
i am trying to work out how to make a draggable movie clip/button continue to move in the same direction as the drag guides it...hmmmm does this make sense???? what is this function / behaviour called.... i have looked at many many drag tutorials but at present have only managed to find drag and drop type onces with target positions.... also does any one know if it is possible assign multiple drag points.
regards....
Video Object - Call To Load And Listener Object Not Working
i've got a video object within a movieclip who's full path i put in a var called 'video'. here's my code, it appears that the video object is not loading my stream and/or i'm not getting the listener object to work properly... everything does trace out good as far as vars, rtmp address, etc... grrr!!!
Code:
//function to load the stream in the vid object
_global.loadVid=function(vidFile){
trace("this is path to vidObj: "+video);
trace("loadVid function var passed: "+vidFile);
var listenerObject:Object = new Object();
listenerObject.ready=function(eventObject:Object):Void{
//video loaded, do this
video.removeEventListener("ready", listenerObject);
_root.container.vidPanel.gotoAndPlay("tovideo");
trace("video is loaded, proceeding to video play state");
};
video.addEventListener("ready", listenerObject);
var nV:String=rtmpURL+vidFile;
video.load(nV, true);
trace("video: "+rtmpURL+vidFile+" should be loading");
}
How'd U Make An Object Snap 2 Its Original Pos On An Object Thats Moved?
I'm working on a school project using Flash mx that needs a scrolling inventory. I know how to get an object to snap back to its original position from a drag, but how would you get it to snap back to its original position on an object that has moved? ie. On a scrolling menu?
//script to have a spanner remove a head and snap back to position if it doesn’t touch the head on release:
//attach to object
onClipEvent (load) {
spanx = _root.spanner._x;
spany = _root.spanner._y;
}
//action inside clip
on (press) {
startDrag(this,true);
}
on (release, releaseOutside) {
if (this.hitTest(_root.dismantle.head) & _root.head_switch=="hollow") {
_root.spanner.gotoAndPlay(2);
_root.dismantle.head.gotoAndPlay(2);
this._y = 185;
_root.airbrush._x= _root.airbrush.airbx;
_root.airbrush._y= _root.airbrush.airby;
}
else {
_root.spanner.gotoAndStop(1);
this._x = spanx;
this._y = spany;
this.gotoAndStop(2);
}
stopDrag();
}
how would i script a scrolling inventory from which I can drag and drop objects that snap back to the same pos in the inventory even tho its moved? You can see the inventory on the right of the attached jpeg.
Papervision Acsess Individual Object Within .dae File/Object
Hello,
The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var storeisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.
Does anyone know how this is acomplished ?
Thanks in Advance.
files at : http://www.kiyoshii.com/transfer/src.zip
Code:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;
public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);
addChild(viewport);
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D(holder, 15, 100);
camera.zoom = 500;
camera.z = -50;
//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);
//DAE
dae = new DAE();
dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));
holder = new DisplayObject3D();
holder.addChild(dae);
holder.rotationX = 90;
holder.rotationY = 45;
scene.addChild(holder);
var store:DisplayObject3D = holder.getChildByName("Loja1");
trace("DAE : " + store);
stage.addEventListener(Event.ENTER_FRAME, renderStuff);
}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}
Web Service Param Is An Object Inside And Array Which Is An Object
Howdy. This is my first time on this forum, and I hope I get more help here than some of the other forums. I'll try to explain my dillema as simply as possible.
I have a webservice. I am calling a method 'InsertSlide'. That method requires and object as the paramater.
the object shcema looks like this:
Object
-SlideID (integer)
-Name (integer)
-SlideTypeID (integer)
-Hits (integer)
-LocationID (integer)
-SwfFileName (integer)
-SlideDataCollection (Array)
- -N (Object)
- - -Label
- - -Value
I hope that makes sense, all I'm trying to get at, is there is an object with an array as a property, that array is populated with an object and it has properties.
I recieve that same ojbect from the webservice fine, but when I send that object like that to the Webservice it does not fully populate my databases, unfortunatly I did not write the webservice.
Is it possible that the problem is the webservice? or flash?
Thanks for any help!
- Kiwi
Targeting Object Properties Inside PopUp Object
In my project I am creating a window using the PopUpManager. The symbol used to create that window has several objects.
For the sake of discussion we'll discuss the object message_txt inside myWindow.
How do I reference message_txt.text from actionscript after the object is dynamically created?
Gravity Issue? Object Slides Through Another Object Instead Of Sitting On Top Of It
Hello!
I have a file where two objects fall from the top of the stage and bounce and then eventually stop (using gravity and hit test).
You can grab the objects (a ball and a box --- each has a button symbol n the movie clip) and toss them and they bounce off each other and off the 4 sides of the stage.
The issue is when one of the objects is dropped directly on top of the other object, after it stops bouncing, it slides down until it hits the bottom of the stage (in this case, the box slides down in front of the ball, and the ball slides down in back of the box).
Is this because the gravity is pulling the object down to the bottom of the stage even though there's another object in its way?
How can I fix this so that the objects will still bounce off each other, and when dropped directly on top of each other object will stop instead of oozing through it (sorry, this is the best way I can describe it ?
I've attached 2 files (Fla 8 and Fla mx 2004).
-------- here is the gravity code on the first frame:
PHP Code:
var gravity:Number = 1.2;
var restitution:Number = 0.6;
var friction:Number = 0.9;
stop();
-------- here is the code on the ball
PHP Code:
onClipEvent(load) {
var dragging:Boolean = false;
var vel:Object = { x: 0, y: 0 };
var pos:Object = { x: _x, y: _y };
var old:Object = { x: _x, y: _y };
var radius:Number = this._width / 2;
var movie:Object = { width: 400, height: 300 };
}
onClipEvent(enterFrame){
if( !dragging ) {
vel.y += _root.gravity;
pos.x += vel.x;
pos.y += vel.y;
if( pos.y + radius > movie.height ) {
pos.y = movie.height - radius;
vel.y *= -_root.restitution;
vel.x *= _root.friction;
}
if( pos.x + radius > movie.width ) {
pos.x = movie.width - radius;
vel.x *= -_root.restitution;
}
if( pos.x < radius ) {
pos.x = radius;
vel.x *= -_root.restitution;
}
_x = pos.x;
_y = pos.y;
} else {
old.x = pos.x;
old.y = pos.y;
pos.x = _x;
pos.y = _y;
vel.x = ( pos.x - old.x ) / 2;
vel.y = ( pos.y - old.y ) / 2;
}
if(this.hitTest(_root.box)) {
trace("hit");
// ball and box are colliding, so lets reverse their movements.
vel.x *= -1;
vel.y *= -1;
_root.box.vel.x*=-1;
_root.box.vel.y*=-1;
/* these actions could be made more realistic by determining the precise
position of the ball relative to the box during the collision, for instance,
determine if the right side is colliding with the left side, so only reverse
the x velocity, instead of both. */
}
//this prevents the ball from leaving the upper extreme of the stage
if (this._y < 0) {
vel.y*=-1;
}
}
-------- here is the code on the button inside the ball (so you can drag and release the ball)
PHP Code:
on(press){
startDrag(this,false,16,16,384,284);
dragging = true;
}
on(release, releaseOutside){
stopDrag();
dragging = false;
}
-------- here is the code on the box
PHP Code:
onClipEvent(load) {
var dragging:Boolean = false;
var vel:Object = { x: 0, y: 0 };
var pos:Object = { x: _x, y: _y };
var old:Object = { x: _x, y: _y };
var radius:Number = this._width / 2;
var movie:Object = { width: 400, height: 300 };
}
onClipEvent(enterFrame){
if( !dragging ) {
vel.y += _root.gravity;
pos.x += vel.x;
pos.y += vel.y;
if( pos.y + radius > movie.height ) {
pos.y = movie.height - radius;
vel.y *= -_root.restitution;
vel.x *= _root.friction;
}
if( pos.x + radius > movie.width ) {
pos.x = movie.width - radius;
vel.x *= -_root.restitution;
}
if( pos.x < radius ) {
pos.x = radius;
vel.x *= -_root.restitution;
}
_x = pos.x;
_y = pos.y;
} else {
old.x = pos.x;
old.y = pos.y;
pos.x = _x;
pos.y = _y;
vel.x = ( pos.x - old.x ) / 2;
vel.y = ( pos.y - old.y ) / 2;
}
}
-------- here is the code on the button inside the box (so you can drag and release the box)
PHP Code:
on(press){
startDrag(this,false,16,16,384,284);
dragging = true;
}
on(release, releaseOutside){
stopDrag();
dragging = false;
}
I appreciate any help anyone can give me to fix this issue, I don't understand enough yet about how these objects are interacting to fix this --- but I hope to learn from you brilliant Kirupians!) Thanks!
Hondo311
Tween Class To Move An Object Called From Within The Object
I have a custom class that I want to move with the Tween Class
I am calling the Tween constructor from within that class but when I pass the keyword "this" as the object of that constructor , it doesnt move at all the code is as follow
PHP Code:
package{import fl.transitions.Tween;import flash.display.MovieClip;public class PortViewer extends MovieClip{var _twn:Tween;public function PortViewer(){ _twn = new Tween(this, "y", None.easeNone, 0, 100, 2, true);}}}
how do I reference the object from within itself is there another keyword?
There are no errors it just doesnt move
Thank you Kirupa forums
AS3 - Papervision Acsess Individual Object Within .dae File/Object
Hello,
The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var store: DisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.
Does anyone know how this is acomplished ?
Thanks in Advance.
files at : http://www.kiyoshii.com/transfer/src.zip
Code:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;
public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);
addChild(viewport);
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D(holder, 15, 100);
camera.zoom = 500;
camera.z = -50;
//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);
//DAE
dae = new DAE();
dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));
holder = new DisplayObject3D();
holder.addChild(dae);
holder.rotationX = 90;
holder.rotationY = 45;
scene.addChild(holder);
var store:DisplayObject3D = holder.getChildByName("Loja1");
trace("DAE : " + store);
stage.addEventListener(Event.ENTER_FRAME, renderStuff);
}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}
Papervision Acsess Individual Object Within .dae File/Object
Hello,
The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var store:DisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.
Does anyone know how this is acomplished ?
Thanks in Advance.
files at : http://www.kiyoshii.com/transfer/src.zip
Code:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;
public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);
addChild(viewport);
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D(holder, 15, 100);
camera.zoom = 500;
camera.z = -50;
//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);
//DAE
dae = new DAE();
dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));
holder = new DisplayObject3D();
holder.addChild(dae);
holder.rotationX = 90;
holder.rotationY = 45;
scene.addChild(holder);
var store:DisplayObject3D = holder.getChildByName("Loja1");
trace("DAE : " + store);
stage.addEventListener(Event.ENTER_FRAME, renderStuff);
}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}
Position Object By Center Of Other Object And Stage Left...?
lol! :lol:
what i mean is i have an object (mc = main_logo) that centers itself upon load:
main_logo._x = Stage.width / 2;
main_logo._y = Stage.height / 2;
and i want another object (mc = helmet) to always load up 2/3rds to the left (x axis) of main_logo's center (counting left to right, 2/3rds between main_logos center and stage left border) and 200 pixels above (y axis) main_logo's center.
i know i keep asking these things and i'm not trying to have you all do every little thing for me, i am trying to learn this! it's just that my brain operates differently and i have to assimalate information by what i'm trying to accomplish...
thanks!
How Do I Move An Object In The Opposite Direction Of Another Object?
Hello,
This seems like it should be easy but for some reason I'm having trouble making it happen... any help would be greatly appreciated.
I know how to set the Y position and get the Y position of objects, but what I'm trying to do is have one object move exactly opposite to another.
The first object is draggable. If it is dragged up 10 pixels, then I want the other object to move down 10 pixels.
Any suggestions?
Thank you!!
Janet
Uploading A Flash Object -- Speed Of Object
If I insert an object into a plain web page -- nothing else on it, in order for that flash object to function, Q: the only thing I upload to the web (besides the page of course) is just the flash object file???
When I saved the file, I see I have two: a Shockwave Flash Object, and a Swish Movie.
So I'm confused on how I saved these files and why I ended up with two?
Are there different methods of saving them? a correct way and an incorrect way?
And how do you take one of these objects/movies and condense it so it still works the same but loads quickly?
pj
Problem Controlling Object From Another Object (scroll Bar)
First time posting here so hope I don't screw up here
Hope I can exlpain my problem and make sense. What I am trying to do control an object from another object. It's a scroll bar moving a block of text. Each line is going to be a button trigering a loadmovie() in a main flash movie. I have a working version of the scroller in a different movie, but in this case the scroller is within another instance. I'm guessing that my instance references are messed up but I can't figure out which ones. I used this tutorial to create this scroller: http://www.flashcircle.com/display.php?storyid=40
Here's a link to the fla:
http://www.httpworkshop.com/navigation.fla
Any help will be greatly appreciated.
Problem Rotating An Object Relating To Another Object...
Hi everyone...
I'm pretty much a newbie, and, naturally, stumped. If anyone can help me out, i would really appreciate it...
I have a lollipop-type object; (it has line/stem that attaches to a circle, fixed to the top of one end).
I want to rotate the object 180 degrees and have it pivot on the end opposite the circle (so the end with the circle appears to swing in an arc). At all times, the circle and the stem must seem to be joined as if they were one solid object. So far, no problem.
However, durning the arc, the stem must shrink in size an x amount. The stems' rotation point must remain fixed; it can't appear to move. The circle must remain it's original size, but still be attached to the stem, thus, the circle's position should gradually be closing up the space left by the shrinking stem at the same time the circle is moving through the arc. And i cannot figure out how to make this work!
To make the rotation work so far, I set the registration pt for the stem at the base of the stem (the pivot pt for it's rotation), set the registration pt for the circle also at the base of the stem (so they would share the same pivot point) and moved the circle to where it would set in relation to the stem. Then for both, i made _rotation = x, and on the stems' enterframe, i added 1 to x for both mcs.
(Also, to complicate the issue, at the beginning of the animation, the stem needs _xscale from 0 to 100, at which point it attaches the circle to it's tip; thus, the necessity of creating two movie clips: one for the stem, one for the circle.)
Thanks again for the help...
Making One Object Move Towards Another Object In Flash 8?
Hi, I need help on making one object move towards another object at a set speed, in Flash Professional 8.
So far I can get one object to move to another one but only doing a fraction of the distance at a time, as with this code:
PHP Code:
onClipEvent (enterFrame) {
var xspd = (this._parent.redsquare._x - this._x) * .1;
var yspd = (this._parent.redsquare._y - this._y) * .1;
this._x += xspd;
this._y += yspd;
}
How can I make it so it moves with a set speed? Anyone able to help?
Convert Object To Strongly Typed Object
I have the following function which serializes my plain obj:Object to custom:SomeObject.
It works great, but if I have ArrayCollection in the Object it would not convert it to my custom object and instead it will just avoid it.
Any help is appreciated...
Here is my code:
Code:
public static function objectToInstance( object:Object, clazz:Class ):*
{
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF0;
// Find the objects and byetArray.writeObject them, adding in the
// class configuration variable name -- essentially, we're constructing
// and AMF packet here that contains the class information so that
// we can simplly byteArray.readObject the sucker for the translation
// Write out the bytes of the original object
var objBytes:ByteArray = new ByteArray();
objBytes.objectEncoding = ObjectEncoding.AMF0;
objBytes.writeObject( object );
// Register all of the classes so they can be decoded via AMF
var typeInfo:XML = describeType( clazz );
var fullyQualifiedName:String = typeInfo.@name.toString().replace( /::/, "." );
registerClassAlias( fullyQualifiedName, clazz );
// Write the new object information starting with the class information
var len:int = fullyQualifiedName.length;
bytes.writeByte( 0x10 ); // 0x10 is AMF0 for "typed object (class instance)"
bytes.writeUTF( fullyQualifiedName );
// After the class name is set up, write the rest of the object
bytes.writeBytes( objBytes, 1 );
// Read in the object with the class property added and return that
bytes.position = 0;
// This generates some ReferenceErrors of the object being passed in
// has properties that aren't in the class instance, and generates TypeErrors
// when property values cannot be converted to correct values (such as false
// being the value, when it needs to be a Date instead). However, these
// errors are not thrown at runtime (and only appear in trace ouput when
// debugging), so a try/catch block isn't necessary. I'm not sure if this
// classifies as a bug or not... but I wanted to explain why if you debug
// you might seem some TypeError or ReferenceError items appear.
var result:* = bytes.readObject();
return result;
}
Convert A Video Object To A Bitmapdata Object
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Camera;
import flash.media.Video;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
public class CameraExample extends Sprite {
private var video:Video;
private var _bitmapData:BitmapData;
private var _bitmapDataDue:BitmapData;
private var mybitmap:BitmapData;
public function CameraExample() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var camera:Camera = Camera.getCamera();
if (camera != null) {
camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
video = new Video(camera.width * 2, camera.height * 2);
video.attachCamera(camera);
addChild(video);
_bitmapData = new BitmapData(video.width , video.height, false);
_bitmapData.draw(video);
var _bitmapDataDisplay:Bitmap = new Bitmap(_bitmapData);
_bitmapDataDisplay.x= camera.width * 2;
addChild(_bitmapDataDisplay);
}
what's wrong with this?
thank yooou
[AS3] XMLDefinition() - XML To Object (object Definitions And Hierarchies In XML)
XMLDefinition is a function that translates XML into ActionScript object definitions. It works a lot like Flex but translates definitions at runtime. As a runtime translater, its limited (no scripting etc) but still flexible in what it can be used to create.
Attached is the class and a simple Flash CS3 example. Below is some documentation. I'll try to include a page with a live demonstration when I get a chance (and if I feel confident that the kinks have been ironed out).
Doc (from the AS file):
XMLDefinition()
Code:
public function XMLDefinition(xml:XML, targetParent:Object = null):Object
Creates an object (typically a display object) based on the definition outlined by the XML. Each XML element represents the object to be made. If that object's definition is in a pacakge, that element will need to be in a namespace whose uri matches that package. The hierarchy of the object created will match the hierarchy of the XML where display objects will be added as children to the display objects. Attributes are used to define properties. If a name attribute is defined, that name will also be used as a property name in the parent to store a reference to the child. If the parent is not a display object container or the child is not a display object and a name attribute is not provided, the child element's index will be used; this is useful when defining arrays as name attributes are not needed.
There are 3 kinds of elements for special uses, each of which defined in the com.senocular.xml.XMLDefinition namespace. They are:
- property
- call
- arguments
The property element is used to access an existing property of an object. For example, you may want to reference the transform property of a MovieClip instance defined in XML rather than redefine it. In that case you would use the property element to access that property's existing value rather than provide a new value to be set for the MovieClip's transform property. This element uses one attribute, name, to determine the name of the property being accessed.
The call element is used to call methods within objects. Like the property element, it too uses the name attribute to identify the class member (in this case a method) to be accessed. This would be useful for calling drawing methods on a display object. Method arguments are handled through the arguments element.
The arguments element is used in combination with class definitions or method calls. For class definitions (elements representing class instances) the arguments element contains the arguments for that instance's constructor call. For method calls, the arguments element's children are used as arguments for that method. The definitions within an arguments block is scoped to the parent node of the arguments element so references to property in an arguments element will reference properties in the argument's parent object. One caveat concerning the arguments element is that you are limited to 10 or less arguments.
The following example creates a Sprite a line drawn in its graphics object and one Shape child object with the instance name "child":
Code:
var definition:XML =
<display:Sprite x="50" y="100"
xmlns:display="flash.display"
xmlns:def="com.senocular.xml.XMLDefinition">
<display:Shape name="child" />
<def:property name="graphics">
<def:call name="lineStyle">
<def:arguments>
<Number>1</Number>
<uint>0xFF0000</uint>
</def:arguments>
</def:call>
<def:call name="lineTo">
<def:arguments>
<Number>100</Number>
<Number>100</Number>
</def:arguments>
</def:call>
</def:property>
</display:Sprite>
var sprite:Sprite = XMLDefinition(definition);
Parameters:
xml - The xml to be parsed into an object.
targetParent - The object in which the generated object will be defined, either as a property or a child display object.
Returns:
A reference to the object created.
Get To An Object's Content From An Object's Event Handler
Hi there,
I have some code that is intended to get a list of XML file names from a PHP script and then parse the content of the XML files and stick certain data into a big array called "allData":
Code:
var allData:Array = new Array();
var remoteFileNames:GetXMLFileNames = new GetXMLFileNames("http://localhost/getVars/getfilenams.php");
remoteFileNames.addEventListener(GetXMLFileNames.GOT_NAMES, getXMLDataFiles);
function getXMLDataFiles(e:Event):void {
for each (var fileName:String in remoteFileNames.fileNames) {
var xmlLoader:XmlLoader = new XmlLoader(fileName);
xmlLoader.addEventListener(XmlLoader.DATA_PARSED, dataParsed);
}
}
function dataParsed(e:Event):void {
trace ("XML data was parsed");
allData.push(???.content); // problem here!
}
(Of course there's also some class files GetXMLFileNames.as and XmlLoader.as that do their stuff) all works well except that I need to get the references to the content property of each object. I guess I do this via the event handler but I'm not sure exactly how? Any one got any ideas?
Many thanks
Ben
So An Object Can't Call Another Object's Methods?
Say I have a conveyor belt object and a trailer truck object.
The conveyor belt adds boxes to itself.
The user clicks on a box and then clicks on 1 of three trailer trucks to put it in.
When box is placed in 1 of the 3 trucks, I'd like the trailer truck to call the conveyor belt's method to cause the conveyor belt to 'add a box' to itself.
If a box is not placed after 4 seconds, the conveyor belt is to call it's 'add a box' method to add another box to itself.
Since the trailer truck mc is also defined as a button, I check to see if it's been clicked on as a way of knowing if a box has been placed inside it and therefore another box should be added to the conveyor belt.
Is it possible to do it this way with oop? I can't seem to do it, but maybe I've got the syntax wrong. If not, how might it be set up with proper oop?
Any Way To Check What Type Of Object The Object Is?
Hey, i was wondering if there is a command to check what type object a certain object is
ex:
function circle(radius){
this.radius = radius
}
functin squre(side){
this.side = side
}
shape1 = new circle(25);
shape2 = new square(10);
//====this is just an example of what i want happen =============
type = getType(shape1)
trace(type);
this will trace "circle"
is there a command that can do is? I thought i saw it somewhere, but i cant find it
Placing Object Over Object By X-Y Coordinates.
This image should basically explain what I'm trying to accomplish right now.
I want an object to move with a moveable object by retreiving the character's X-Y coordinates and then placing the object by the X-Y coordinates of the hero until the animation is complete. How can I do this?
Thanks for your help.
Object In Object Retrieving Question
Hello,
For an assingment at college I am creating a multi-user realtime game.
Therefor I am using the Electroserver by Electrotank. Because of latency I want to create the game-engine in a server-side script.
Code:
var variables = new Object();
for(var i=1; i<=8; i++) {
variables[i] = new Object();
for(var j=1; j<=8; j++) {
ob = new Object();
ob.type = 0;
variables[i][j] = ob;
}
}
When I trace this code at the serverside like variables[2][3].type I get the number zero (which is what I want (seems quite unlogical, but in the rest of the script this ob.type is set to a random numberand that is all working as it should)). It seems that things are done in some sort of Javascript at the server (server is programmed in java, server-side scripts can be done in either java or actionscript), cause I get something like org.mozilla.javascript errors in the server outputwindow.
But when I send the object variables to the client and I trace it there the same way (variables[2][3]) I get the message undefined.
When I do the trace variables[2] I get [object Object], so there is something. And now comes the actual question.
How can I get to the properties of this object in variables[2]? Do I have to do it with some kind of dot-syntax?
I hope you can help me figure it out.
Tnx in advance,
Jorrit
|