I am new to as3. I have developed a small application which in as3. But issue is the sprite created does not dispatch any mouse events [ eg: click ]. Please can anyone guide me and throw some comment
.... private var progressBarHolder:Sprite = new Sprite();
progressBarHolder.graphics.clear();
progressBarHolder.graphics.beginFill(0xeaeaea);
progressBarHolder.alpha = 0.5;
progressBarHolder.graphics.drawRoundRect(0, 0, 80, 25, 0,0);
//progressBarHolder.graphics.endFill();
progressBarHolder.width = progressBarWidth;
progressBarHolder.height = 24;
progressBarHolder.x = 48;
progressBarHolder.y = _videoModule.getHeight() - 48;
progressBarHolder.buttonMode = true;
progressBarHolder.addEventListener(MouseEvent.CLICK, progressBarHolderClick);
_overlay.addChild(progressBarHolder);
.....
Thanks!
Code looks ok, possible problems:
width and height of your sprite are not zero (progressBarWidth != 0)
mouse is enabled on parent (_overlay), to make sure use -
progressBarHolder.mouseEnabled = true;
make sure there is nothing above progressBarHolder on the Z index that is blocking the click from the sprite.
Your code is correct. Look up on _overlay or progressBarHolderClick listener. Also It's can happens if property mouseChildren of _overlay or other parent set as false.
Show more code if you still can't find solution.
Related
I have a button class which contains event listeners to trigger an animation of the button on click.
I used many instances of this class to form a list which the user can scroll through. I have implemented BlitMask, this works, however the mouse event listeners in the button class no longer work. This code
_blit = new BlitMask(_mc, _obounds.x, _bounds.y, _bounds.width, _bounds.height, false);
Is what stops the button class.
How can I get the behaviour pre blitmark?
My code which creates the bottom is
var tf:TextField = new TextField(text);
tf.x = 70;
tf.y = 20;
_btn.addChild(tf);
_btn.addEventListener(MouseEvent.CLICK, click);
click is never called.
The blitmask causes the movieclip to be nothing more than an image of clip.
bitmapMode must be set to false to correct this.
_blitMask.bitmapMode = false;
EDIT: To expand on a further issue that implementing this solution causes, turning bitmapMode on only when needed causes the bitmap to not reflect changes in the classes that changed while bitmapMode was off. So you must set
_blitMask.update(null, true);
To force a full update when you use
_blitMask.bitmapMode = true;
I'm trying to add a few text boxes so that people can select text and copy it to their clipboard.
I wrote the following, but the problem is that the text box stays through all the frames after it's been accessed and I just want it to stay in that frame. Do I have to set them on invisible elsewhere? How come other frames even have access to this code?
Any solutions? Thanks!
stop();
var myFont = new fontCandy();
var myFormat:TextFormat = new TextFormat();
myFormat.size = 10;
myFormat.font = myFont.fontName;
myFormat.color = 0xFFFFFF;
var myText:TextField = new TextField();
myText.defaultTextFormat = myFormat;
myText.embedFonts = true;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.text = "my#email.com";
addChild(myText);
myText.border = true;
myText.wordWrap = true;
myText.width = 100;
myText.height = 15;
myText.x = 70;
myText.y = 185;
In FlashPro, anything done in code is not subject to timeline keyframes. Something done in code will persist until it's scope (the timeline it's on) is unloaded or you've explicitly cleaned it up via code. (though certain things can keep your objects in memory even after this).
This also includes display objects that originated on the timeline (not through code) but have had their parentage or positioning manipulated via code (so if you use addChild/setChildIndex on a timeline object)
You have to explicitly remove it by using removeChild(instanceOrVarName);
So in your case: removeChild(myText); will remove that text field.
So, to sum it up:
Things done through code must be cleaned up through code.
Here are a few options for you to explore:
call removeChild(myText) on the very next frame
listen for the ENTER_FRAME event and check if the playhead has moved, if so then do removeChild(myText) and remove the listener.
on the frame you have this code, put a text field on the stage (just on that frame), give it an instance name of myText, then keep the code you have except for the new TextField() line, and the addChild line. This should make it do what you want but also let it be removed on the next frame.
I have this annoying issue that I hope someone might be able to help me with.
I have a mute button that I created and I have another movieclip inside of that button. All I want it to do is when I toggle the mute the movieclip inside will go to the according frame.
However, every time I try to call the movieclip inside of the button, this error comes up:
Access of possibly undefined property mcMuteToggle through a reference with static type flash.display:SimpleButton.
The instance name for the movieclip within is "mcMuteToggle".
Why not make movieClips that act like buttons?? Since I dont think actual button (simpleButton) types can deal with sub-MovieClips (especially if they too have code). Even if possible don't do it, I can predict a mess whereby Button does things it shouldn't do depending on what code you have in those MClips.
Try an alternate button method, just for a test... You didnt show any test code to work with so I will make assumptions..
1) Make a shape (rectangle?) and convert to MovieClip (or if all coded, then addchild shape to new MovieClip). Let's assume you called it mc_testBtn.
2) Make that MC clickable by coding mc_testBtn.buttonMode = true;
3) Add your mcMuteToggle inside the mc_testBtn
(or by code: mc_testBtn.addChild(mcMuteToggle);
Now you can try something like..
mc_testBtn.addEventListener (MouseEvent.CLICK, toggle_Mute );
function toggle_Mute (evt:MouseEvent) : void
{
if ( whatever condition )
{
mc_testBtn.mcMuteToggle.gotoAndStop(2); //go frame 2
}
else
{
mc_testBtn.mcMuteToggle.gotoAndStop(1); //go frame 1
}
}
This is likely due to strict mode. You can either disable it in the ActionScript settings dialog, access it with a different syntax myButton['mcMuteToggle'], or make a class for the symbol that includes a property mcMuteToggle.
You can also check to make sure the symbol is actually on the stage and that clip is actually in the button:
if('myButton' in root) {
// ...
}
if('mcMuteToggle' in myButton) {
// ...
}
i think u just overwrite that codes. You u can use something like this:
var soundOpen:Boolean = true;
var mySound:Sound = new Sound(new URLRequest("Whatever your sound is"));
var mySc:SoundChannel = new SoundChannel();
var mySt:SoundTransform = new SoundTransform();
mySc = mySound.play();
mcMuteToggle.addEventListener(MouseEvent.CLICK, muteOpenSound);
function muteOpenSound(e:MouseEvent):void
{
if(soundOpen == true)
{
mcMuteToggle.gotoAndStop(2);
/*on frame 2 u need to hold ur soundClose buton so ppl can see :)*/
soundOpen = false;
mySt.volume = 0;
mySc.soundTransfrom = st;
}
else
{
mcMuteToggle.gotoAndStop(1);
soundOpen = true;
mySt.volume = 1;
mySc.soundTransfrom = st;
}
}
This is working for me everytime. Hope u can use it well ;)
I have a problem with my StageText field not dispatching the keyboard events. StageText is implemented on an AS3 only project. Everything works fine except that when I hit the return key, nothing happens...
below follows my code:
_input = new StageText(new StageTextInitOptions(true));
_input.text = _trackerData.trackerComment;
_input.maxChars = Globals.TRACKER_INPUT_CHARS;
_input.fontFamily = "Antenna Regular";
_input.softKeyboardType = SoftKeyboardType.DEFAULT;
_input.returnKeyLabel = ReturnKeyLabel.DONE;
_input.autoCorrect = true;
_input.fontSize = ScreenUtils.cmToPt(.25);
_input.color = 0x000000;
_input.fontWeight = "normal";
_input.stage = this.stage;
_input.viewPort = new Rectangle( ScreenUtils.cmToPx(.35),
ScreenUtils.cmToPx(1.5),
stage.stageWidth - ScreenUtils.cmToPx(.7),
ScreenUtils.cmToPx(3)
);
_input.addEventListener(KeyboardEvent.KEY_UP, keyUpEventHandler);
private function keyUpEventHandler(evt:KeyboardEvent):void
{
trace("keyCode", evt.keyCode);
}
But the function is never getting called!
Anybody knows what the problem may be?
Thanks in advance!
I can't find why, but if you use the ReturnKeyLabel.DONE, it don't work! Try with another, like ReturnKeyLabel.GO
You need to add the event listener BEFORE setting the viewport property
objectToBeMasked.mask = maskObject;
Ok, simple... but I can SEE the maskObject unless I set its alpha to 0 and then it doesn't let clicks through to objectToBeMasked
And every single tutorial that I've seen fails to mention this and how to solve it, as if it should be obvious.
How do I mask objects through AS3 so that the masks act like masks act like the ones added in the IDE?
Here is an example :
var maskedShape : Shape = new Shape();
maskedShape.graphics.beginFill(0x0);
maskedShape.graphics.drawRect(0, 0, 100, 100);
maskedShape.graphics.endFill();
addChild(maskedShape);
var maskerShape : Shape = new Shape();
maskerShape.graphics.beginFill(0x0);
maskerShape.graphics.drawRect(0, 0, 100, 100);
maskerShape.graphics.endFill();
addChild(maskerShape);
maskerShape.x = 20;
maskerShape.y = 20;
maskedShape.mask = maskerShape;
You shouldn't see the mask. Probably the mask and the masked object are not on the stage at the time you are trying to apply the mask.
Can you pass on some code here?
The easiest way is to not render your object simply bt setting visible parameter to false :
maskObject.visible = false;
so your objectToBeMasked is still masked, but do not catch mouse event, and is not rendered anymore :)