Hi All
I want to know how can we assingn an instance name for a movie clip or sprite created dynamically
i have used .name and its working fine !!
but i am not able to call it from another function!!
//////////----------------------------------- here is the code
import flash.display.Sprite;
import flash.display.LineScaleMode;
import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.Shape;
//------
function thumbDown(e:MouseEvent):void
{
trapezoid1.y+= trapezoid1.y*.02;
}
//------
//-----------------------------------
i dont want to write the code in the draw_trapezoid function
if i write there its working perfect
but i want to access and assign events from another function
//---- this is very simple and basic question but i was stuck up here and struggling hard to handle projects in as3
I’m not sure what goal of this exercise actually is.
I couldn’t decide what “trapezoid.y+= trapezoid.y*.02;” is supposed to do.
Here’s my 2¢…
//I added Tweenmax to the script to see if it would function; it does.
//I also used Sprite instead of Shape. Shape would not work with TweenMax.
stop();
import gs.TweenMax;
import fl.motion.easing.*;
import flash.display.Sprite;
import flash.display.LineScaleMode;
import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.Shape;
var trapezoid:Sprite = new Sprite();
addChild(trapezoid);
trapezoid.name = 'trapezoid1';
function draw_trapezoid() {
with (trapezoid.graphics) {
lineStyle(10, 0xFFD700, 1, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 10);
moveTo(100, 100);
lineTo(120, 50);
lineTo(200, 50);
lineTo(220, 100);
lineTo(100, 100);
}
}
draw_trapezoid();
trapezoid.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown, false, 0, true);
function thumbDown(e:MouseEvent):void {
TweenMax.to(trapezoid, 1, {y:200});//used this value to get some feedback.
trace(e.target.name);
//traces "trapezoid1" as expected; not sure about the relevance of the .name property here.
//it's certainly not required for tweening.
}
Essentially the variable name by which you declare an object IS its instance name, and it cannot be dynamic. But you can have other vars reference it which means you can use array keys for dynamic naming.
With respect to your montage you have two options.