Flex 4.5 - addChildToSandboxRoot? - apache-flex

In Flex 3.2 I had implemented a tooltip manager and I used the topLevelSystemManager from ISystemManager to add a child to the sandbox root:
The code was as follows:
var sm:ISystemManager = getSystemManager(currentTarget) as ISystemManager;
sm.topLevelSystemManager.addChildToSandboxRoot("toolTipChildren" , currentToolTip as DisplayObject);
In my endeavour to upgrade Flex to 4.5 I discovered that this method does no longer exist.
What's the appropriate way of migrating this piece of code to 4.5?
Part of the ActionScript class is shown here:
mx_internal function createTip():void
{
// Dispatch a "createToolTip" event
// from the object displaying the tooltip.
var event:ToolTipEvent =
new ToolTipEvent(ToolTipEvent.TOOL_TIP_CREATE);
currentTarget.dispatchEvent(event);
if (event.toolTip)
currentToolTip = event.toolTip;
else
currentToolTip = new toolTipClass();
currentToolTip.visible = false;
var sm:ISystemManager = getSystemManager(currentTarget) as ISystemManager;
sm.topLevelSystemManager.addChildToSandboxRoot("toolTipChildren", currentToolTip as DisplayObject);
}
Any help will be greatly appreciated.

Use the tooltip manager, as explained here.

turns out I can just use this
sm.topLevelSystemManager.toolTipChildren.addChild(currentToolTip as DisplayObject)

Related

Flex 4.6 Need to know how to animate a .swf in actionscript

I've converted a PowerPoint into Flash so each slide is a .swf. I've used a number of different converters and the problem here is the same.
What I'd like to do is trigger the .swf's animation (contents of slide appearing) programatically. I can click on the .swf with a mouse and the animation advances. I can automate this when the .swf's embedded in a web page simply by doing:
document.getElementById('myMovie').play();
Each time I execute that code, the swf advances to the next animation. However, I can't find a way to do this in flex. I've used then MovieClipSWFLoader and tried:
private function animate():void {
var simulatedClick1:MouseEvent = new MouseEvent(MouseEvent.CLICK);
var simulatedClick2:MouseEvent = new MouseEvent(MouseEvent.MOUSE_DOWN);
var simulatedClick3:MouseEvent = new MouseEvent(MouseEvent.MOUSE_UP);
frameNo++;
myMovie.gotoAndStop(frameNo);
myMovie.nextFrame();
myMovie.nextScene();
myMovie.play();
myMovie.dispatchEvent(simulatedClick1); // with clicks 1, 2, and 3
}
<s:MovieClipSWFLoader id="myMovie" source=""/>
<s:Button id="btnAnimate" click="animate()"/>
I've also tried loading as an Image component and using the simulated click too... no good. Can anyone tell me how I can do this?
The problem was that the .swf was created with Flash 8 and wasn't compatible with my version of Flex. I found a great solution in ForcibleLoader at https://gist.github.com/nsdevaraj/409902. It converts old .swf's to new ones and then the code worked as it should.
private var libMC:MovieClip = new MovieClip();
ur = new URLRequest(guide_url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
var fLoader:ForcibleLoader = new ForcibleLoader(loader);
fLoader.load(ur);
swfMovie.addChild(loader);
private function swfComplete(event:Event):void{
libMC = event.currentTarget.content as MovieClip;
}
private function animate():void {
libMC.nextFrame();
<mx:UIComponent id="swfMovie"/>

Context Menu is not working in flash player 10.1

I write a flex application. I added some custom menu items in context menu. when I compiled this code using flashplayer 10.0, it works fine and my added context menu items are shown when I Right-Click. But when I compile same code for flashPlayer 10.1, menu items that I added in context menu are not shown when I Right-Click. What should I do to resolve this issue?
I am using sdk 3.5.
Any help or suggestion will be appreciated.
I am doing this;
private var cm:ContextMenu = new ContextMenu();
var versionMenu:ContextMenuItem = null;
var dateMenu:ContextMenuItem = null;
if(model.appVersion.length > 0)
{
versionMenu = new ContextMenuItem(model.appVersion);
}
if(model.releaseDate.length > 0)
{
dateMenu = new ContextMenuItem(model.releaseDate);
}
cm.hideBuiltInItems();
var cmArray:Array = new Array();
if(versionMenu != null)
cmArray.push(versionMenu);
if(dateMenu != null)
cmArray.push(dateMenu);
cm.customItems = cmArray;
Thanks.
there is no reason. It works fine for me in flashPlayer 10.1 . Also it is listed as supported in 10.1 here : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html
alert the isSupported property in code to double check (it will most definitely be true).
If you are trying to create a context menu for Application then here is the correct code:
<s:Application ... initialize="init();">
private function init():void
{
var versionItem:ContextMenuItem = new ContextMenuItem("Version 1.5.443");
contextMenu.hideBuiltInItems();
contextMenu.customItems = [ versionItem ];
}
</s:Application>

context menu is not display in web project in flex

context menu is working well in desktop project but not display in web project...........kindly help and suggest if anyone has some suitable answer
In main.mxml, on application initialize, run this function:
private function init():void {
var customMenuItem1:ContextMenuItem = new ContextMenuItem(“WHATEVER DUDE”);
var contextMenuCustomItems:Array = application.contextMenu.customItems;
contextMenuCustomItems.push(customMenuItem1);
}

Add Child immediately in Flex 3

I'm having a problem similar to FLEX: dialog not display immediately . Code follows:
private function saveBitmap(event:ContextMenuEvent):void
{
loadingScreen.visible = true;
loadingScreen.appLoadingText.text = "Preparing bitmap...";
addChild(loadingScreen);
validateNow();
var bmpd:BitmapData = new BitmapData(canv.width, canv.height);
bmpd.draw(canv);
var fr:FileReference = new FileReference();
fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, removeLoadingScreen);
fr.addEventListener(Event.CANCEL, removeLoadingScreen);
var png:PNGEncoder = new PNGEncoder();
var iba:ByteArray = png.encode(bmpd);
fr.save(iba, "export.png");
}
Basically, bmpd.draw and/or png.encode are dog slow, so I'd like to have a nice "please hold while we prepare your png" dialog to appear. I can't use callLater() because of the FileReference.
And just for good measure, the loading screen appears at the same time the save dialog appears from the call to fr.save().
Any ideas?
Cheers!
You're adding the child in this function. Are you doing any other work to the loadingScreen, such as sizing it? Or positioning it? Most commonly this is done in updateDisplayList(). What container are you using?
Are you sure the Z-order of your two children is correct? You can swap children with the swapChildren method

Create a button with an icon in actionscript

I want to create buttons with icons in Flex dynamically using Actionscript.
I tried this, with no success:
var closeButton = new Button();
closeButton.setStyle("icon", "#Embed(source='images/closeWindowUp.png");
I found an answer that works for me. In my .mxml file, I create Classes for the icons I will use:
// Classes for icons
[Embed(source='images/closeWindowUp.png')]
public static var CloseWindowUp:Class;
[Embed(source='/images/Down_Up.png')]
public static var Down_Up:Class;
[Embed(source='/images/Up_Up.png')]
public static var Up_Up:Class;
In the Actionscript portion of my application, I use these classes when dynamically creating buttons:
var buttonHBox:HBox = new HBox();
var closeButton:Button = new Button();
var upButton:Button = new Button();
var downButton:Button = new Button();
closeButton.setStyle("icon", SimpleWLM.CloseWindowUp);
buttonHBox.addChild(closeButton);
upButton.setStyle("icon", SimpleWLM.Up_Up);
buttonHBox.addChild(upButton);
downButton.setStyle("icon", SimpleWLM.Down_Up);
buttonHBox.addChild(downButton);
You can use this one option of dynamic change of button icon.
Embed your icons
[Embed(source='com/images/play.png')]
[Bindable]
public var imagePlay:Class;
[Embed(source='com/images/pause.png')]
[Bindable]
public var imagePause:Class;
Using one button to toggle play and pause of video
private function playpause():void
{
if (seesmicVideo.playing)
{
seesmicVideo.pause();
btn_play.setStyle("icon",imagePlay);
}
else
{
seesmicVideo.play();
btn_play.setStyle("icon",imagePause);
}
}
The error is in the quotes, there should be no quotes around the #Embed:
closeButton.setStyle("icon", #Embed(source="images/closeWindowUp.png"));
I was able to use an icon in my button with the following code:
<mx:Button id="buttonPlay" label="Play" click="playButtonClicked();" enabled="false" icon="#Embed('./play.png')"/>
the file play.png is in the same folder of the mxml file.
I am using Flash Builder version 4.6.
Edit: the question was about ActionScript and not MXML, but I leave this answer just for reference.
I'm assuming you're adding it to the stage?
Also, I think your Embed is missing a close quote / paren.
closeButton.setStyle("icon", "#Embed(source='images/closeWindowUp.png");
should be:
closeButton.setStyle("icon", "#Embed(source='images/closeWindowUp.png')");

Resources