How would I go about converting my actionscript 3 (on the timeline) into a class? As I am using the same functionality across multiple FLA files.
// IMPORTS
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.external.ExternalInterface;
// VARIABLES
mcToolTip.toolTip.blendMode = BlendMode.LAYER;
mcToolTip.toolTip.text = "";
var toolio = false;
var settext;
var urlButton1:String = 'URL STRING 1';
var urlButton2:String = 'URL STRING 1';
var urlButton3:String = 'URL STRING 1';
var urlButton4:String = 'URL STRING 1';
var urlButton5:String = 'URL STRING 1';
// MISC
mcButton1.stop();
mcButton2.stop();
mcButton3.stop();
mcButton4.stop();
mcButton5.stop();
mcButton1.buttonMode = true;
mcButton2.buttonMode = true;
mcButton3.buttonMode = true;
mcButton4.buttonMode = true;
mcButton5.buttonMode = true;
// EVENT LISTENERS
//button1
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,button1Text);
mcButton1.addEventListener(MouseEvent.MOUSE_DOWN,callButton1);
mcButton1.addEventListener(MouseEvent.CLICK,mclick);
//button2
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,button2Text);
mcButton2.addEventListener(MouseEvent.MOUSE_DOWN,callButton2);
mcButton2.addEventListener(MouseEvent.CLICK,mclick);
//button3
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,button3Text);
mcButton3.addEventListener(MouseEvent.MOUSE_DOWN,callButton3);
mcButton3.addEventListener(MouseEvent.CLICK,mclick);
//button4
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,button4Text);
mcButton4.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton4.addEventListener(MouseEvent.CLICK,mclick);
//button5
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,button5Text);
mcButton5.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton5.addEventListener(MouseEvent.CLICK,mclick);
// FUNCTIONS
function mclick(e:MouseEvent):void {
toolio = true;
e.currentTarget.gotoAndStop(5);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,mout);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,mover);
settext = mcToolTip.toolTip.text;
if (e.currentTarget !== mcButton2) {
mcButton2.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton3) {
mcButton3.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton4) {
mcButton4.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton1) {
mcButton1.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton5) {
mcButton5.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
}
function mover(e:MouseEvent):void {
stopPlayReverse(e.currentTarget as MovieClip);
e.currentTarget.play();
var fadeIn:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 0, 1, 0.5, true);
}
function mout(e:MouseEvent):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc !== null) {
mc.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
if ( toolio == false ) {
var fadeOut:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 1, 0, 0.5, true);
}
if (settext != undefined) {
mcToolTip.toolTip.text = settext;
}
}
function playReverse(e:Event):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc.currentFrame == 1) {
stopPlayReverse(mc);
} else {
mc.prevFrame();
}
}
function stopPlayReverse(mc:MovieClip):void {
if ((mc!==null) && mc.hasEventListener(Event.ENTER_FRAME)) {
mc.removeEventListener(Event.ENTER_FRAME, playReverse);
}
}
function button1Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 1"; }
function button2Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 2"; }
function button3Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 3"; }
function button4Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 4"; }
function button5Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 5"; }
function callButton1(evt:MouseEvent):void { ExternalInterface.call("button1", urlButton1);}
function callButton2(evt:MouseEvent):void { ExternalInterface.call("button2", urlButton2);}
function callButton3(evt:MouseEvent):void { ExternalInterface.call("button3", urlButton3); }
function callButton4(evt:MouseEvent):void { ExternalInterface.call("button4", urlButton4);}
function callButton5(evt:MouseEvent):void { ExternalInterface.call("button5", urlButton5);}
First thing, it appears you have "Automatically declare stage instances" checked in your settings. I avoid this like the plague. Follow the directions here: under "disabling stage instance auto-declaration." Unchecking that box will force you to declare your other stage instances, like mcToolTip and the mcButtons. But it will help in future development efforts (trust me.)
Anyway, I figured this would be your document class since you said it was used per swf. I named it MyFirstClass, you probably want a better name. You need to chance "BOTH" instances of that name... one in the class signature "public class MyFirstClass extends MovieClip" and the second in the constructor (the function with the same name as the class) which gets run as soon as the class is "instantiated"
Put this file in the same directory as your .fla. Add "MyFirstClass" as the document class.
Read up on more info about how to write your own class: here
package {
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.external.ExternalInterface;
impprt flash.display.MovieClip;
public class MyFirstClass extends MovieClip {
public var toolio = false;
public var settext;
public var urlButton1:String = 'URL STRING 1';
public var urlButton2:String = 'URL STRING 1';
public var urlButton3:String = 'URL STRING 1';
public var urlButton4:String = 'URL STRING 1';
public var urlButton5:String = 'URL STRING 1';
public function MyFirstClass():void {
mcToolTip.toolTip.blendMode = BlendMode.LAYER;
mcToolTip.toolTip.text = "";
mcButton1.stop();
mcButton2.stop();
mcButton3.stop();
mcButton4.stop();
mcButton5.stop();
mcButton1.buttonMode = true;
mcButton2.buttonMode = true;
mcButton3.buttonMode = true;
mcButton4.buttonMode = true;
mcButton5.buttonMode = true;
// EVENT LISTENERS
//button1
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,button1Text);
mcButton1.addEventListener(MouseEvent.MOUSE_DOWN,callButton1);
mcButton1.addEventListener(MouseEvent.CLICK,mclick);
//button2
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,button2Text);
mcButton2.addEventListener(MouseEvent.MOUSE_DOWN,callButton2);
mcButton2.addEventListener(MouseEvent.CLICK,mclick);
//button3
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,button3Text);
mcButton3.addEventListener(MouseEvent.MOUSE_DOWN,callButton3);
mcButton3.addEventListener(MouseEvent.CLICK,mclick);
//button4
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,button4Text);
mcButton4.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton4.addEventListener(MouseEvent.CLICK,mclick);
//button5
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,button5Text);
mcButton5.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton5.addEventListener(MouseEvent.CLICK,mclick);
}
// FUNCTIONS
public function mclick(e:MouseEvent):void {
toolio = true;
e.currentTarget.gotoAndStop(5);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,mout);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,mover);
settext = mcToolTip.toolTip.text;
if (e.currentTarget !== mcButton2) {
mcButton2.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton3) {
mcButton3.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton4) {
mcButton4.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton1) {
mcButton1.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton5) {
mcButton5.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
}
public function mover(e:MouseEvent):void {
stopPlayReverse(e.currentTarget as MovieClip);
e.currentTarget.play();
var fadeIn:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 0, 1, 0.5, true);
}
public function mout(e:MouseEvent):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc !== null) {
mc.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
if ( toolio == false ) {
var fadeOut:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 1, 0, 0.5, true);
}
if (settext != undefined) {
mcToolTip.toolTip.text = settext;
}
}
public function playReverse(e:Event):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc.currentFrame == 1) {
stopPlayReverse(mc);
} else {
mc.prevFrame();
}
}
public function stopPlayReverse(mc:MovieClip):void {
if ((mc!==null) && mc.hasEventListener(Event.ENTER_FRAME)) {
mc.removeEventListener(Event.ENTER_FRAME, playReverse);
}
}
public function button1Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 1"; }
public function button2Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 2"; }
public function button3Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 3"; }
public function button4Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 4"; }
public function button5Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 5"; }
public function callButton1(evt:MouseEvent):void { ExternalInterface.call("button1", urlButton1);}
public function callButton2(evt:MouseEvent):void { ExternalInterface.call("button2", urlButton2);}
public function callButton3(evt:MouseEvent):void { ExternalInterface.call("button3", urlButton3); }
public function callButton4(evt:MouseEvent):void { ExternalInterface.call("button4", urlButton4);}
public function callButton5(evt:MouseEvent):void { ExternalInterface.call("button5", urlButton5);}
}
}
I like to generalize as much as possible. You did a good thing by calling the buttons and movieclips with numbers after them, but you're missing out on one of the advantages to doing that which is that you can now generalize event handlers.
This is what I came up with by editing the code sberry2A posted:
package {
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.external.ExternalInterface;
import flash.display.MovieClip;
public class MyFirstClass extends MovieClip {
public var toolio = false;
public var settext;
public var buttonSettings :Object;
public function MyFirstClass():void {
buttonSettings = {
1: {
url: "http://example.org",
tooltip: "Some text here"
},
2: {
url: "http://example.org",
tooltip: "Some text here"
},
3: {
url: "http://example.org",
tooltip: "Some text here"
},
4: {
url: "http://example.org",
tooltip: "Some text here"
},
5: {
url: "http://example.org",
tooltip: "Some text here"
}
};
mcToolTip.toolTip.blendMode = BlendMode.LAYER;
mcToolTip.toolTip.text = "";
initializeButtons();
addEventListeners();
}
// FUNCTIONS
public function initializeButtons():void {
for(var i:String in buttonSettings) {
this["mcButton"+i].stop();
this["mcButton"+i].mouseChildren = false;
this["mcButton"+i].buttonMode = true;
this["mcButton"+i].useHandCursor = true;
}
}
public function addEventListeners():void {
for(var i:String in buttonSettings) {
this["mcButton"+i].addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
this["mcButton"+i].addEventListener(MouseEvent.MOUSE_OUT,handleMouseOut);
this["mcButton"+i].addEventListener(MouseEvent.CLICK,handleMouseClick);
}
}
public function addPlayReverseListenerButSkip(skip:String = null):void {
for(var i:String in buttonSettings) {
if(skip && skip == i) { continue; }
this["mcButton"+i].addEventListener(Event.ENTER_FRAME, playReverse);
}
}
public function handleMouseClick(e:MouseEvent):void {
toolio = true;
e.target.gotoAndStop(5);
e.target.removeEventListener(MouseEvent.MOUSE_OUT,mout);
e.target.removeEventListener(MouseEvent.MOUSE_OVER,mover);
settext = mcToolTip.toolTip.text;
var targetNumber :String = e.target.name.split("mcButton").join("");
addPlayReverseListenerButSkip(targetNumber);
if(ExternalInterface.available) {
ExternalInterface.call("button" + targetNumber, buttonSettings[targetNumber].url);
}
}
public function handleMouseOver(e:MouseEvent):void {
var mc :MovieClip = e.target as MovieClip;
stopPlayReverse(mc);
mc.play();
var targetNumber = e.target.name.split("mcButton").join("");
setTooltipTextTo(targetNumber);
var fadeIn:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 0, 1, 0.5, true);
}
public function handleMouseOut(e:MouseEvent):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc !== null) {
mc.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
if ( toolio == false ) {
var fadeOut:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 1, 0, 0.5, true);
}
if (settext != undefined) {
mcToolTip.toolTip.text = settext;
}
}
public function stopPlayReverse(mc:MovieClip) {
if ((mc!==null) && mc.hasEventListener(Event.ENTER_FRAME)) {
mc.removeEventListener(Event.ENTER_FRAME, playReverse);
}
}
public function playReverse(e:Event):void {
var mc :MovieClip = e.target as MovieClip;
if (mc.currentFrame == 1) {
stopPlayReverse(mc);
}
else {
mc.prevFrame();
}
}
public function setTooltipTextTo(targetNumber:String):void {
mcToolTip.toolTip.text = buttonSettings[targetNumber].tooltip;
}
}
}
This code isn't tested, but with a little debugging, you should be able to get this working like the code above.
Related
I am looking for some guidance to create a custom Spark List ItemRenderer for an Flex Mobile application I am developing.
Overview: Section List where each item has a checkbox control, Label, button control 1 - opens an accordion list below the item, button control 2 - opens Camera UI.
What I am struggling with is creating an itemrenderer that allows the accoridion list to be visible and be populated.
Update: Here's my existing code
<fx:Metadata>
[Event(name="checkBoxIconItemRendererChanged", type="flash.events.Event")]
[Event(name="cameraIconItemRendererChanged", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import spark.components.Label;
import spark.components.CheckBox;
import spark.components.HGroup;
import spark.components.Image;
import spark.layouts.HorizontalAlign;
import flashx.textLayout.formats.VerticalAlign;
//camera stuff
public var cameraIcon:Image;
public var friendsIcon:Image;
//checkbox stuff start
public var checkBox:CheckBox;
private var checkBoxChanged:Boolean;
private var _checkBoxField:String;
private var _checkBoxFunction:Function;
//list item group
public var listGroup:HGroup;
private var dataSource:IDataInput;
public function get checkBoxFunction():Function{
return _checkBoxFunction;
}
public function get checkBoxField():String{
return _checkBoxField;
}
public function set checkBoxFunction(value:Function):void{
if(_checkBoxFunction==value){
return;
}
_checkBoxFunction=value;
checkBoxChanged=true;
invalidateProperties();
}
public function set checkBoxField(value:String):void{
if(_checkBoxField==value){
return;
}
checkBoxChanged=true;
_checkBoxField=value;
invalidateProperties();
}
/*override public function set data(value:Object):void
{
checkBoxChanged=true;
super.data = value; //->invalidateProperties();
}*/
override protected function createChildren():void
{
super.createChildren();
listGroup = new HGroup();
var testLabel:Label = new Label();
testLabel.text = "Test Item";
listGroup.addElement(testLabel);
//listGroup.addChild(testLabel);
listGroup.visible = false;
listGroup.includeInLayout = false;
addChild(listGroup);
checkBox = new CheckBox();
//checkBox.skin = skins.ChallengeCheckBox; //throws error in the Skin
checkBox.width=64;//32
checkBox.height=64;//32
checkBox.scaleY=1;//.5
checkBox.scaleX=1;//.5
addChild(checkBox);
//listGroup.addChild(checkBox);
checkBox.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void{
dispatchEvent(new Event("checkBoxIconItemRendererChanged"));
});
friendsIcon = new Image();
friendsIcon.source = "assets/controls/eye_lightgray.png";
friendsIcon.verticalAlign = VerticalAlign.MIDDLE;
//cameraIcon.horizontalAlign = HorizontalAlign.RIGHT;
friendsIcon.width = 85;
friendsIcon.height = 85;
//cameraIcon.x = 275;
friendsIcon.x = Capabilities.screenResolutionX - 205;
friendsIcon.buttonMode = true;
friendsIcon.addEventListener(MouseEvent.CLICK,showFriends);
addChild(friendsIcon);
//listGroup.addChild(friendsIcon);
cameraIcon = new Image();
cameraIcon.source = "assets/controls/uncheckedbox.png";
friendsIcon.verticalAlign = VerticalAlign.MIDDLE;
//cameraIcon.horizontalAlign = HorizontalAlign.RIGHT;
cameraIcon.width = 85;
cameraIcon.height = 85;
//cameraIcon.x = 275;
cameraIcon.x = Capabilities.screenResolutionX - 105;
cameraIcon.buttonMode = true;
cameraIcon.addEventListener(MouseEvent.CLICK,launchCameraUI);
addChild(cameraIcon);
}
override protected function measure():void
{
super.measure();
measuredWidth+=getStyle("horizontalGap")+checkBox.width*checkBox.scaleY;
measuredHeight=Math.max(measuredHeight, checkBox.height*checkBox.scaleY);
}
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number):void
{
var paddingLeft:Number = getStyle("paddingLeft");
var paddingRight:Number = getStyle("paddingRight");
var paddingTop:Number = getStyle("paddingTop");
var paddingBottom:Number = getStyle("paddingBottom");
var horizontalGap:Number = getStyle("horizontalGap");
var verticalAlign:String = getStyle("verticalAlign");
setStyle("paddingLeft",paddingLeft+checkBox.width*checkBox.scaleX+horizontalGap);
super.layoutContents(unscaledWidth, unscaledHeight);
setStyle("paddingLeft",paddingLeft);
var vAlign:Number;
if (verticalAlign == "top")
vAlign = 0;
else if (verticalAlign == "bottom")
vAlign = 1;
else // if (verticalAlign == "middle")
vAlign = 0.5;
var viewHeight:Number = unscaledHeight - paddingTop - paddingBottom;
var checkBoxDisplayY:Number = Math.round(vAlign * (viewHeight - checkBox.height*checkBox.scaleY)) + paddingTop;
checkBox.x=paddingLeft;
checkBox.y=checkBoxDisplayY;
}
override protected function commitProperties():void
{
super.commitProperties();
if(checkBoxChanged){
checkBoxChanged=false;
if (checkBoxFunction != null)
{
checkBox.selected=checkBoxFunction(data);
}
else if (checkBoxField)
{
try
{
if (checkBoxField in data && data[checkBoxField] != null)
checkBox.selected=data[checkBoxField];
}
catch(e:Error)
{
trace(e.message);
}
}
}
}
//end
private var _backgroundSection:Number = 0xDDDDDD; //this is a grey
public function set backgroundSection(value:Number):void {
_backgroundSection = value;
}
private var _normalLabelField:String = "kick";
public function get normalLabelField():String {
return _normalLabelField;
}
public function set normalLabelField(value:String):void {
_normalLabelField = value;
}
private var _sectionField:String = "points";
public function get sectionField():String {
return _sectionField;
}
public function set sectionField(value:String):void {
if (value == _sectionField)
return;
_sectionField = value;
invalidateProperties();
}
/**
* Change the style based on the data: section item or regular item
*/
override public function set data(value:Object):void {
//checkbox
checkBoxChanged=true;
if (value[_sectionField]) {
labelField = _sectionField;
labelDisplay.setStyle("textAlign", "center");
labelDisplay.setStyle("fontWeight", "bold");
} else {
labelField = _normalLabelField;
labelDisplay.setStyle("textAlign", "left");
labelDisplay.setStyle("fontWeight", "normal");
//labelDisplay.width = 300;
//labelDisplay.wordWrap = true;
//labelDisplay.multiline = true;
}
super.data = value;
}
override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
super.drawBackground(unscaledWidth, unscaledHeight);
//change the background if we render for a section title item
if (data[_sectionField]) {
graphics.beginFill(_backgroundSection, 1);
graphics.lineStyle();
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.endFill();
//adding .parent to each, adding listGroup as parent reference
/*if (checkBox.parent.parent != null)
listGroup.removeChild(checkBox);
if (friendsIcon.parent.parent != null)
listGroup.removeChild(friendsIcon);*/
if (checkBox.parent != null)
removeChild(checkBox);
if (friendsIcon.parent != null)
removeChild(friendsIcon);
if (cameraIcon.parent != null)
removeChild(cameraIcon);
}
}
protected function launchCameraUI(event:MouseEvent):void
{
var cUI:CameraRoll = new CameraRoll();
if( CameraRoll.supportsBrowseForImage )
{
cUI.addEventListener( MediaEvent.SELECT, imageSelected );
cUI.addEventListener( Event.CANCEL, browseCanceled );
cUI.addEventListener( ErrorEvent.ERROR, mediaError );
cUI.browseForImage();
}
else
{
trace( "Image browsing is not supported on this device.");
}
}
protected function imageSelected(event:MediaEvent):void
{
trace( "Media selected..." );
var imagePromise:MediaPromise = event.data;
dataSource = imagePromise.open();
if( imagePromise.isAsync )
{
trace( "Asynchronous media promise." );
var eventSource:IEventDispatcher = dataSource as IEventDispatcher;
eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );
}
else
{
trace( "Synchronous media promise." );
readMediaData();
}
}
protected function browseCanceled(event:Event):void
{
// TODO Auto-generated method stub
}
protected function mediaError(event:ErrorEvent):void
{
// TODO Auto-generated method stub
}
private function onMediaLoaded( event:Event ):void
{
trace("Media load complete");
readMediaData();
}
private function readMediaData():void
{
//do something with the data
}
protected function showFriends(event:MouseEvent):void
{
// TODO Auto-generated method stub
if (listGroup.visible == true)
{
listGroup.visible = false;
listGroup.includeInLayout = false;
trace("Hide Friends Drop Down");
}
else
{
listGroup.visible = true;
listGroup.includeInLayout = true;
trace("Show Friends Drop Down");
}
}
]]>
</fx:Script>
Im using the following as the base code: http://corlan.org/2011/07/04/creating-flex-mobile-section-lists/
UPDATE: Ultimately I would like to create the following layout where the checkbox is independent of the list item & when you touch the eye icon it opens an accordian style list:
I didn't really know what exactly to ask in the question. So I am going to explain everything here:
I am working on a Desktop AIR Database Application I have a Class named "Database Screen" which is linked to a movie clip:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.InteractiveObject;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextField;
public class DatabaseScreen extends MovieClip {
private var allButtons:Array;
private var codeSelected:Boolean;
private var nameSelected:Boolean;
private var xmlDatabase:XML;
private var dbFile:File;
public var xmlList:XMLList;
private var totalProducts:uint;
private var totalItems:uint = 0;
private var productExists:Boolean;
private var productId:Number;
private var XMLReader:xmlReader;
public function DatabaseScreen() {
allButtons = [searchPanel.search_btn, addNewPanel.addNew_btn, dbStatsPanel.xls_btn, searchPanel.code_radio, searchPanel.name_radio];
init();
}
private function init():void
{
XMLReader = new xmlReader();
//adding event listeners..
for(var i:int = 0; i<allButtons.length; i++)
{
allButtons[i].addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_DOWN, onDown, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);
allButtons[i].addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
allButtons[i].buttonMode = true;
}
//creating a new file for the database
dbFile = File.documentsDirectory.resolvePath("BlackCat/Database.xml");
xmlDatabase = new XML();
getXML();
saveXML();
getTotalItems();
dbStatsPanel.items.text = String(totalItems);
}
private function getXML():void
{
if(dbFile.exists)
{
var stream:FileStream = new FileStream();
stream.open(dbFile, FileMode.READ);
xmlDatabase = new XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
xmlList = xmlDatabase.Product;
dbStatsPanel.products.text = xmlList.length();
XMLReader.xmlData = xmlList;
XMLReader.updateXMLList(xmlList);
}
else
{
xmlDatabase = <Products></Products>
}
}
public function getXMlList():XMLList
{
return xmlList;
}
private function getTotalItems():void
{
for(var i:int = 0; i < xmlList.length(); i++)
{
totalItems += uint(xmlList[i].#Qty);
}
}
private function saveXML():void
{
var stream:FileStream = new FileStream();
stream.open(dbFile, FileMode.WRITE);
stream.writeUTFBytes(xmlDatabase.toXMLString());
}
private function onDown(evt:MouseEvent):void
{
evt.target.scaleX = evt.target.scaleY = .8;
}
private function onUp(evt:MouseEvent):void
{
evt.target.scaleX = evt.target.scaleY = 1;
}
private function onOver(evt:MouseEvent):void
{
evt.target.alpha = .5;
}
private function onOut(evt:MouseEvent):void
{
evt.target.alpha = 1;
evt.target.scaleX = evt.target.scaleY = 1;
}
private function onClick(evt:MouseEvent):void
{
switch(evt.target.name)
{
case "code_radio":
codeSelected = true;
nameSelected = false;
searchPanel.code_radio.gotoAndStop(1);
searchPanel.name_radio.gotoAndStop(2);
break;
case "name_radio":
nameSelected = true;
codeSelected = false;
searchPanel.code_radio.gotoAndStop(2);
searchPanel.name_radio.gotoAndStop(1);
break;
case "addNew_btn":
//Checking if the product already exists..
for(var i:int = 0; i < xmlList.length(); i++)
{
if(xmlList[i].#code == addNewPanel.add_code_txt.text)
{
productExists = true;
productId = i;
}
}
if(productExists)
{
var PQty:uint = uint(xmlList[productId].#Qty);
var PQtoAdd:uint = uint(addNewPanel.add_qty_txt.text);
PQty += PQtoAdd;
xmlList[productId].#Qty = String(PQty);
productExists = false;
}
else
{
xmlDatabase.appendChild(<Product code={addNewPanel.add_code_txt.text}
name={addNewPanel.add_name_txt.text} Price={addNewPanel.add_price_txt.text}
Qty={addNewPanel.add_qty_txt.text}></Product>);
}
totalItems += uint(addNewPanel.add_qty_txt.text);
xmlList = xmlDatabase.Product;
dbStatsPanel.products.text = xmlList.length();
dbStatsPanel.items.text = String(totalItems);
XMLReader.updateXMLList(xmlList);
saveXML();
trace(xmlDatabase);
break;
}
}
public function setVisiblity(visibility:Boolean):void
{
switch(visibility)
{
case true:
this.visible = true;
break;
case false:
this.visible = false;
break;
}
}
public function getXMLList():XMLList
{
return xmlList;
}
}
}
And I have another class named "NewOrder", in this class I am trying to access the xmlList from the "DatabaseScreen" class but I am unable to do so.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
public class NewOrder extends MovieClip {
private var allButtons:Array;
private var shoppingCart:Array;
private var scroller:FlickScroll;
private var db:DatabaseScreen;
private var XMLReader:xmlReader;
public function NewOrder() {
this.visible = false;
init(db);
}
private function init(dbase:DatabaseScreen):void
{
XMLReader = new xmlReader();
trace(XMLReader.xmlData);
scroller = new FlickScroll(masker, container, 84.05, -500);
addChild(scroller);
allButtons = [scan_btn, print_invoice];
shoppingCart = [];
for(var i:int = 0; i < allButtons.length; i++)
{
allButtons[i].addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_DOWN, onDown, false, 0, true);
allButtons[i].addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);
allButtons[i].mouseChildren = false;
allButtons[i].buttonMode = true;
}
}
private function onOver(evt:MouseEvent):void
{
evt.target.alpha = .5;
}
private function onOut(evt:MouseEvent):void
{
evt.target.alpha = 1;
evt.target.scaleX = evt.target.scaleY = 1;
}
private function onDown(evt:MouseEvent):void
{
evt.target.scaleX = evt.target.scaleY = .8;
}
private function onUp(evt:MouseEvent):void
{
evt.target.scaleX = evt.target.scaleY = 1;
if(evt.target.name == "scan_btn")
{
var cartElement:CartElement = new CartElement();
container.addChild(cartElement);
cartElement.x = 0;
cartElement.alpha = 0;
TweenMax.to(cartElement, .4, {alpha:1});
shoppingCart.push(cartElement);
cartElement.id_txt.text = String(shoppingCart.length) + " - ";
if(shoppingCart.length < 2)
{
cartElement.y = container.height - 30;
}
else
{
cartElement.y = container.height + 5;
}
}
}
}
}
And there is a Main class in which I handle all the screens , e.g DatabaseScreen, NewOrder.. Which means I have added these to the display list in the Main class. To access the xmlList from the DatabaseScreen , I tried creating a new instance in the NewOrder class, but it creates to DatabaseScreen(s). I also tried creating another class named "xmlReader":
package {
public class xmlReader {
public var xmlData:XMLList;
public function xmlReader() {
}
public function updateXMLList(updatedList:XMLList):void
{
xmlData = updatedList;
}
}
}
In the databaseScreen class, as soon as I populate the xmlList , I set the xmlData of the xmlReader class equal to the xmlList from the databaseScreen class. And when I trace the XMLReader.xmlData in the databaseScreen , it works fine . But when I do the same thing in the NewOrder class, I get "null" in the output window.
How do I solve this problem. Any help is greatly appreciated.
You will need to pass a reference into the Order class to have access to the DatabaseScreen class. Something like this.
var ds = new DatabaseScreen();
var or = new NewOrder(ds)
Inside the NewOrder you can save the ref.
public class NewOrder {
private var screens:DatabaseScreens;
public function NewOrder(ds:DatabaseScreens) {
screens = ds;
// Now you can call screens.xmlList
}
}
This is basically just drag and double click to set (so drag is temporarily disabled) but the sprite doesn't keep with the mouse- can someone point me to better code- otherwise I'll with go with this- so much more to do.
//The initial event performed when the button is first clicked;
internal var m_nDoubleClickSpeed:Number = 300;
internal var m_toMouse:Number;
internal var moveready:Boolean = false;
internal var initalx:uint;
internal var initialy:uint;
internal var move:Boolean;
internal function clickDoubleClick(e:MouseEvent):void {
if (isSet == false) {
this.startDrag();
}
if (isNaN(m_toMouse)==false) {
clearTimeout(m_toMouse);
HandleDoubleClick();
} else {
m_toMouse = setTimeout(HandleSingleClick, m_nDoubleClickSpeed);
}
}
internal function HandleSingleClick():void {
trace("HandleSingleClick");
trace("isSet");
trace(isSet);
this.stopDrag();
m_toMouse = NaN;
}
internal function HandleDoubleClick():void {
if (isSet == false) {
isSet = true;
this.stopDrag()
} else {
isSet = false;
}
trace("HandleDoubleClick");
m_toMouse = NaN;
}
internal function goodX(inX:Number):Number {
if (inX < 0) {
return 0;
}
if (inX > (stage.stageWidth) ) {
return (stage.stageWidth);
}
return inX;
}
internal function goodY(inY:Number):Number {
if (inY < 0) {
return 0;
}
if (inY > stage.stageHeight) {
return stage.stageHeight;
}
return inY;
}
I'm not sure if I understood you correctly. So you want to start drag on single click and drag until doubleclicked right? If so you can try something like that:
public class ClickAndDrag extends Sprite
{
private var clickTimeout:uint;
private var doubleClickSpeed:int = 500;
private var clickedOnce:Boolean;
private var mouseOnClick:Point;
private var isDragging:Boolean;
public function ClickAndDrag()
{
graphics.beginFill(Math.random()*0xffffff, 1);
graphics.drawCircle(0, 0, 20);
graphics.endFill();
this.buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
}
private function handleMouseDown(e:MouseEvent):void
{
if (isDragging)
{
if (clickedOnce)
handleDoubleClicked();
else
{
//if it's not clicket within next doubleClickSpeed ms then doubleClickSpeed will be set to false;
clickedOnce = true;
clickTimeout = setTimeout( handleClickTimeout, doubleClickSpeed );
}
}
else
{
handleClickAndDrag();
}
}
//clicked once when dragging
private function handleClickOnce():void
{
graphics.clear();
graphics.beginFill(Math.random()*0xffffff, 1);
graphics.drawCircle(0, 0, 20);
graphics.endFill();
}
//clicked once when not dragging
private function handleClickAndDrag():void
{
isDragging = true;
this.addEventListener(Event.ENTER_FRAME, handleFrame);
mouseOnClick = new Point(this.mouseX, this.mouseY);
}
//doubleclicked when dragging
private function handleDoubleClicked():void
{
clearTimeout(clickTimeout);
clickedOnce = false;
this.removeEventListener(Event.ENTER_FRAME, handleFrame);
isDragging = false;
}
private function handleClickTimeout():void
{
clickedOnce = false;
handleClickOnce();
}
private function handleFrame(e:Event):void
{
this.x = stage.mouseX - mouseOnClick.x;
this.y = stage.mouseY - mouseOnClick.y;
}
}
It basically waits for mousedown and if it's already dragging it checks if you clicked once (changes color) ot twice (stops dragging). Or if it's not dragging yet then it starts dragging. You may also want to handle leaving the stage (Event.MOUSE_LEAVE).
Essentially, the spawning ships appear above the crosshair whereas I want it to be the other way around. I tried adding the crosshair to another layer but then clicking / 'shooting' the ships does nothing. Any ideas?
public class Main extends MovieClip {
public static var backgroundLayer:Sprite = new Sprite();
public static var gameLayer:Sprite = new Sprite();
public static var interfaceLayer:Sprite = new Sprite();
public static var menuLayer:Sprite = new Sprite();
public var mainMenu:menuMain = new menuMain();
public var intro:IntroSound = new IntroSound();
public var soundControl:SoundChannel = new SoundChannel();
public var crosshair:crosshair_mc;
static var enemyArray:Array = [];
private var enemyShipTimer:Timer;
private var enemyShipTimerMed:Timer;
private var enemyShipTimerSmall:Timer;
public function Main()
{
addMenuListeners();
addChild(gameLayer);
addChild(backgroundLayer);
addChild(interfaceLayer);
addChild(menuLayer);
menuLayer.addChild(mainMenu);
interfaceLayer.addChild(howtoPlay);
interfaceLayer.addChild(gameEnd);
interfaceLayer.addChild(gameAbout);
soundControl = intro.play(0, 100);
stage.addEventListener(Event.ENTER_FRAME, update);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
}
private function update(e:Event):void
{
for each (var enemy:EnemyShip in enemyArray)
{
enemy.update();
if (enemy.dead)
{
enemy.kill();
}
}
}
private function mouseDown(e:MouseEvent):void
{
if (e.target.name) {
switch (e.target.name) {
case "enemy_big":
updateScore(5);
e.target.parent.damage();
break;
case "enemy_medium":
updateScore(10);
e.target.parent.damage();
break;
case "enemy_small":
updateScore(15);
e.target.parent.damage();
break;
}
}
}
function addMenuListeners():void
{
//Code to add event listeners
}
public function startGame(e:Event)
{
removeMenuListeners();
soundControl.stop();
if (howtoPlay.parent == interfaceLayer)
{
interfaceLayer.removeChild(howtoPlay);
}
if (gameAbout.parent == interfaceLayer)
{
interfaceLayer.removeChild(gameAbout);
}
if (gameEnd.parent == interfaceLayer)
{
interfaceLayer.removeChild(gameEnd);
}
if (mainMenu.parent == menuLayer)
{
menuLayer.removeChild(mainMenu);
}
enemyShipTimer = new Timer(2000);
enemyShipTimer.addEventListener("timer", sendEnemy);
enemyShipTimer.start();
enemyShipTimerMed = new Timer(2500);
enemyShipTimerMed.addEventListener("timer", sendEnemyMed);
enemyShipTimerMed.start();
enemyShipTimerSmall = new Timer(2750);
enemyShipTimerSmall.addEventListener("timer", sendEnemySmall);
enemyShipTimerSmall.start();
crosshair = new crosshair_mc();
gameLayer.addChild(crosshair);
crosshair.mouseEnabled = crosshair.mouseChildren = false;
Mouse.hide();
gameLayer.addEventListener(Event.ENTER_FRAME, moveCursor);
resetScore();
}
function spawnEnemy(type:String, speed:Number) {
var enemy = new EnemyShip(type, speed);
enemyArray.push(enemy);
gameLayer.addChild(enemy);
return enemy;
}
function sendEnemy(e:TimerEvent):void
{
Timer(e.currentTarget).delay = (1+Math.random()*2)*1000;
spawnEnemy("big", Math.random() * 5 + 12);
}
function sendEnemyMed(e:TimerEvent):void
{
Timer(e.currentTarget).delay = (1+Math.random()*2)*1000;
spawnEnemy("medium", Math.random() * 7 + 14);
}
function sendEnemySmall(e:TimerEvent):void
{
Timer(e.currentTarget).delay = (1+Math.random()*2)*1000;
spawnEnemy("small", Math.random() * 9 + 16);
}
static function updateScore(points)
{
score += points;
scoreText.text = String(score);
scoreHeader.setTextFormat(scoreFormat);
scoreText.setTextFormat(scoreFormat);
}
static function resetScore()
{
score = 0;
scoreText.text = String(score);
scoreText.setTextFormat(scoreFormat);
}
static function removeEnemy(enemyShip:EnemyShip):void {
enemyArray.splice(enemyArray.indexOf(enemyShip), 1);
gameLayer.removeChild(enemyShip);
}
function moveCursor(event:Event)
{
crosshair.x=mouseX;
crosshair.y=mouseY;
}
}
}
I expect MouseDowns are intercepted by the parent layer. You have employed mouseEnabled=false for crosshair, now you should do that for its parent.
public static var crosshairLayer:Sprite=new Sprite();
public function Main() {
... // initialize everything first
addChild(gameLayer);
addChild(crosshairLayer);
crosshairLayer.mouseEnabled=false;
crosshairLayer.mouseChildren=false;
}
Then you add crosshair to crosshairLayer.
I'm a very beginner in as3. I want to make a box with two parallel movie clips loaded on mouse hover and rewinded on mouse out. I'd like to add links to movie clips, but after a long time I've ended up with nothing.
Code looks like this:
import flash.events.MouseEvent;
for (var fl_ChildIndex:int = 0;
fl_ChildIndex < this.numChildren;
fl_ChildIndex++)
{
this.getChildAt(fl_ChildIndex).addEventListener(MouseEvent.MOUSE_OVER, nawierzch);
}
function nawierzch(event:MouseEvent):void
{
this.addChild(event.currentTarget as DisplayObject);
}
zlec.stop();
zlec.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
zlec.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
zlec.addEventListener(MouseEvent.CLICK, onClick);
zlec.buttonMode = true;
zlec.mouseChildren = true;
function onClick(event:MouseEvent):void
{
trace("click")
var url:String = "http://www.motoopcja.pl";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
function onMouseOver(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
mc.removeEventListener(Event.ENTER_FRAME, rewind);
mc.play();
mc.addEventListener(Event.ENTER_FRAME, advance);
}
function onMouseOut(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
mc.removeEventListener(Event.ENTER_FRAME, advance);
mc.prevFrame();
mc.addEventListener(Event.ENTER_FRAME, rewind);
}
function advance(e:Event):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
if (mc.currentFrame == mc.totalFrames)
{
mc.stop();
mc.removeEventListener(Event.ENTER_FRAME, advance);
}
}
function rewind(e:Event):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
if (mc.currentFrame == 1)
{
mc.stop();
mc.removeEventListener(Event.ENTER_FRAME, rewind);
}
else
{
mc.prevFrame();
}
}
wykonaj.stop();
wykonaj.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver2);
wykonaj.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut2);
wykonaj.addEventListener(MouseEvent.CLICK, onClick2);
wykonaj.buttonMode = true;
wykonaj.mouseChildren = true;
function onClick2(e:MouseEvent):void
{
trace("click")
}
function onMouseOver2(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
mc.removeEventListener(Event.ENTER_FRAME, rewind);
mc.play();
mc.addEventListener(Event.ENTER_FRAME, advance);
}
function onMouseOut2(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
mc.removeEventListener(Event.ENTER_FRAME, advance);
mc.prevFrame();
mc.addEventListener(Event.ENTER_FRAME, rewind);
}
function advance2(e:Event):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
if (mc.currentFrame == mc.totalFrames)
{
mc.stop();
mc.removeEventListener(Event.ENTER_FRAME, advance);
}
}
function rewind2(e:Event):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
if (mc.currentFrame == 1)
{
mc.stop();
mc.removeEventListener(Event.ENTER_FRAME, rewind);
}
else
{
mc.prevFrame();
}
}
The problem can be that you don't import everything you need.
You must also be carefull not to remove an eventlistener that doesn't exist.
That can happen very often in your code. Here is an example:
zlec is rolled over.
zlec has the rewind eventlistener removed (doesn't exist).
I don't know if you have some outside AS3 that prevents it, but it can throw an error.
This is a much cleaner solution:
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.events.Event;//imports
zlec.addEventListener(MouseEvent.ROLL_OVER,turnPar);
zlec.addEventListener(MouseEvent.ROLL_OUT,turnPar);
zlec.addEventListener(MouseEvent.CLICK,clickedBox);
zlec.buttonMode = true;//make the cursor change on roll over
for(var curChild:uint=0;curChild<this.numChildren) {
this.getChildAt(curChild).addEventListener(Event.ENTER_FRAME,playPar);
}
var theState:String = "MouseEvent.ROLL_OUT";//by default rewind to frame 1
function turnPar(event:MouseEvent):void { theState = event.type; }
function clickedBox(event:MouseEvent):void {
var url:String = "http://www.motoopcja.pl";//your website
var req:URLRequest = new URLRequest(url);//as URLRequest
navigateToURL(req,'_blank');//open in a new window
}
function playPar(event:Event):void {
if("MouseEvent.ROLL_OUT" == theState && event.currentTarget.currentFrame > 1) { event.currentTarget.prevFrame(); }
else if("MouseEvent.ROLL_OVER" == theState && event.currentTarget.currentFrame < event.currentTarget.totalFrames) { event.currentTarget.nextFrame(); }
}