Localizing component labels at run-time - actionscript-3

I have a few different tabs in a navigator defined like this : (removed client specific domain)
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:container="com.*****.shop.admin.container.*"
width="100%" height="100%"
implements="com.*****.common.container.IScreen"
xmlns:services="com.****.shop.admin.services.*"
label="Service Types">
I have resource bundles for different locales, en_US looks like this :
ServicesScreen.label=Service Types
When I try to do this, it doesn't work :
...
...
label="{resourceManager.getString('resources','ServicesScreen.label')}"
Instead of getting my resource bundle entry, I get something weird looking in my GUI like :
Shop0.ShopSkin9._ShopSkin_Group1.contentScroller.ScrollerSkin13.contentGroup.vsMain.AdminView154.SkinnableContainerSkin159.contentGroup.subNavItems.opCodeScreen
My resource bundles work in other cases, for instance labels next to form input fields, etc... The code compiles, however, and no errors are actually thrown (compile or run-time). I tried assigning the value to a variable and using that variable in the label field, however that caused a compile error.
I tried calling a setter method on creation complete of the component, but that didn't resolve the issue either.
How do I localize my tab labels, and can I do so dynamically at run-time?
Thanks for your time!

I guess I'll self-answer this one, although credit goes to Sunil D. I don't know why it didn't work earlier while I was testing, I must've missed something the first time, but here goes. first I added:
creationComplete="init(event)">
And then in that method body I did :
protected function init(event:FlexEvent):void
{
this.label = resourceManager.getString('resources','opCodeScreen.title');
}
And it works like a charm. honestly I'm pretty sure I did this exact same test this morning, but I guess not. Sunil If you want to make your comment an answer I'll go ahead and accept it.
EDIT: change the text at run-time, add currentStateChange that calls aforementionned method
Cheers!

Related

Reusing Angular component with different input

I have ran into a strange problem that I'm not really sure where to begin investigating of what could cause it. I'm currently using a library, angular-stl-model-viewer that uses Three.js. I call a component that renders a 3D model. However, when I call the component again and add a different file both components have both parts even though each component was assigned one different part file.
Ex.
<div class="row">
<stl-model-viewer stlModel="model/teapot"
class="col-5"></stl-model-viewer>
<span class="col-2"></span>
<stl-model-viewer stlModel="model/other"
class="col-5"></stl-model-viewer>
</div>
2 different components first should just be a teapot with part in the middle
Image of both parts in both components
I feel like the component is being referenced as one even though it's there twice. Is there a way to make each invoke of the component unique and separate? Also I understand this may have been asked before but didn't really know what word or phrase to search. Sorry about this and thanks for the help.
Temporary fix might be :-
<stl-model-viewer *ngIf="showModel" stlModel="model/teapot"
For eg:- if you are changing filename in a method :-
changeFileName() {
this.showModel = false;
//file Name Changing Code Here
setTimeout(()=>{this.showModel=true});
}
As you won't get a fix soon. One use posted same question 26 days ago :-
https://github.com/tevim/angular-stl-model-viewer/issues/389#issue-605311429

PhpStorm autocomplete __construct method

When you write public function __ PhpStorm prompt's a list of Magic Methods
So if you, for instance, want to create a constructor for your class, you would use __construct magic method. For example, I typed __con and PhpStorm detect's my intention of creating a constructor thus a prompt window suggests me to auto-create one.
Once you hit Enter the method is created.
While this is pretty nice, I would really love to have the cursor automatically placed between parenthesis like this: public function __construct(|) (the vertical bar "|" illustrates the cursor), and that would give me the ability to write the params needed for the constructor, in case I don't need any properties, I could press Tab and the cursor would move to the body of the method like this:
public function __construct()
{
|
}
From what I read in PhpStorm documentation, I did not found anywhere to be mentioned that you can edit those suggestions by PhpStorm, so I believe that in order to archive what I'm describing I have to go with a live template like this:
So my question is: Is my approach the only way to archive that or there is a way to edit the PhpStorm build-in suggestion for the class constructor magic method?
Thanks!
This is a known problem, please vote for WI-33646.

When creating custom layouts in Flex, why do you "have to" override updateDisplayList() and measure()?

When creating custom layouts in Flex, you generally override LayoutBase, in which case the documentation and tutorials on the Internet say you "have to" override the functions updateDisplayList() and measure(). . .Huh?
I don't think there is a construct in AS3 to syntactically require a function to be overridden, and there sure isn't one here. There's not even as special logic to raise unhandled Errors or anything. This works perfectly fine:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns="*" backgroundColor="#000000" showStatusBar="false" click="createImage()">
<fx:Script>
<![CDATA[
import spark.components.Image;
[Embed(source="AL.png")]
private static const IMAGE:Class;
private var iX:int = 0;
private var iY:int = 0;
private function createImage():void
{
var img:Image = new Image();
img.source = IMAGE;
img.width = 100;
img.height = 100;
img.x = iX
img.y = iY;
iX += 100;
iY += 100;
grp.addElement(img);
}
]]>
</fx:Script>
<s:Group id="grp" width="400" height="400">
<s:layout>
<GridLayout/>
</s:layout>
</s:Group>
</s:WindowedApplication>
And in my GridLayout.as class:
package
{
import spark.layouts.supportClasses.LayoutBase;
public class GridLayout extends LayoutBase
{
}
}
Each time I click on the application, a new image is spawned at (x, y) * n, where n is the number of images previously spawned. It works perfectly fine. I even added code so that right-clicking would take an already existing image and move it around on the screen, and that worked fine as well.
So I guess my question is. . .Why in the world are they saying this is absolutely required? What do they mean? I can understand the documentation and stuff saying that those two functions are where you want to concentrate your customizations at or something like that, but in programming, saying that a function override is required is some pretty strong language; if stuff holds up just fine without you overriding those functions, why would both documentation and independent tutorials be saying this? Thanks!
Why in the world are they saying this is absolutely required?
Since I don't know what documentation you're reading; it is tough to say. The documentation could be wrong; or you could be taking something out of context. It is not required that you write any sort of code in an updateDisplayList() or measure() method, but...
What do they mean?
In the context of creating Flex components; it makes sense to make use of the Flex Component LifeCycle methods, for either MX components or Spark Components. The lifecycle methods (createChildren(), commitProperties(), updateDisplayList(), and measure() are executed by the Flex Framework and make use of an invalidation cycle built right into the framework.
The framework methods help you put "similar" code in the same place so you don't have it all over the place.
The Spark Framework changed things a bit by providing the option of separating layout and sizing code (AKA updateDisplayList() and measure() out of the main class and into a specific layout class.
saying that a function overload is required is some pretty strong
language
I'd be surprised if you've read any docs that say that overloading is required. Overloading is the act of creating multiple functions with the same name, but different arguments. This is not supported in ActionScript. Overriding is the act of extending a function in a child component in order to change or extend functionality of that function. They are different concepts; and I'm unclear if that was a typo on your part or if you are confused about some tenants of object oriented programming.
Does this help? [Unfortunately, I don't have the time right now to try to re-work your sample to make proper use of Flex Framework conventions.
Why in the world are they saying this is absolutely required?
I understand your concern, these overriding functions are required for the components to works optimally. These components don't require to follow these component lifecycle principles if your applications is small, the component does not change frequently and no body else touches your class.
But, If your app needs to change these components frequently then you might have enforce these lifecycle principles.
For example: you want to Prepare Coke, steps(I'd say life cycle) would be take water > mix sugar > add colors > mix soda > bottle it
Now you get orders to change the color of the Coke that you just prepared, the life cycle is already completed, if you need to change anything at this point, you need to put a lot of effort even to change the color of it. If you had followed the life cycled, it makes life easier for the app at run time. No performance issues.

photoshop activeDocument

I am writing a Photoshop plug in in ActionScript 3.
I am having a very confusing and frustrating issue with app.activeDocument. My code works perfectly with Photoshop for Windows but on a Mac I get the "General Photoshop errooccurreded. This Functionality may not be available in this version of Photoshop." error.
To try and get to the root of the issue, I wrote a class just to get the document reference and called it from a test panel. The class call worked perfectly. I then included the same class in my main panel project and it breaks.
This is my class: -
package DocRefGetter
{
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.*;
public class DocRefPhotoshop
{
public static function getDocRef():Document
{
var app:Application = Photoshop.app;
var thisDoc:Document = app.activeDocument;
//var thisDoc:Document = app.documents.index(0); //Tried this method too
return thisDoc;
}
}
}
For the purpose of posting here, I have simplified things a little, i.e. I have removed things like the "try, catch" statements but essentially this is the code that does not work in the context of my panel. I also tried the equivalent call to JSX code with exactly the same result, worked perfectly for Windows, worked in a test panel on Mac, would not work in my main project on Mac.
As I said, inside a test, this works perfectly. Here is the test mxml code: -
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
<mx:Script>
<![CDATA[
import DocRefGetter.DocRefPhotoshop;
import com.adobe.photoshop.Document;
[Bindable]
private var hostName:String = HostObject.mainExtension;
protected function button1_clickHandler(event:MouseEvent):void
{
var thisDocRef:Document = DocRefPhotoshop.getDocRef();
testLabel.text = String(thisDocRef);
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Run PS code" click="button1_clickHandler(event)" />
<mx:Label id="testLabel" width="182" text="Label"/>
</mx:VBox>
</mx:Application>
I can't post the main application that it isn't working in as it is extremely large and complicated so what I am asking is has anyone come across a situation before where somehow something is conflicting with this type of document reference? I have been trying to resolve this for over a week now. I have tried many different solutions but nothing has worked. Mac Photoshop just simply doesn't want to see the open document.
Any suggestions are welcome but I am hoping most that someone has come across this exact situation before and has a precise solution.
Many thanks for taking the trouble to take a look at this.
so what I am asking is has anyone come across a situation before where somehow something is conflicting with this type of document reference?
Use one of the following checks:
Is docref null?
Is the document loaded asynchronously?
Is the document large enough to warrant a timeout?
References
Scripting Photoshop: Working with the document model
Adobe Photoshop CS5 Scripting Guide (pdf)
JavaScript development toolkit | Download Adobe ExtendScript Toolkit CC

Obtain reference to View in ActionScript class within ViewNavigatorApplication

I've got a very simple project in FlashBuilder 4.5. It's a mobile application of type ViewNavigatorApplication with a single view, MapView. In the MapView.mxml file, I've got a Flex component of type Map declared in xml.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" name="CatBusMapView">
<fx:Script>
<![CDATA[
import com.esri.ags.Map;
....
]]>
</fx:Script>
<fx:Declarations>
....
</fx:Declarations>
<esri:Map id="cbm">
...
</esri:Map>
</s:View>
In this same project, I've an actionscript class called UserGeolocation. In this class, I'm attempting to get a reference to this map component.
So far, I can get a reference to the top-level application, its ViewNavigator and the NavigationStack of said ViewNavigator. However, I cannot find a way to access the MapView, much less the map I've declared within it.
I'm aware of methods like firstView() and activeView(), but I want an absolute solution, one that retrieves the view regardless of whether or not it's first or active. I've tried navigator.getChildByName("MapView") with no luck.
You could also do it using events. Fire a custom event from the MapView onActivate/creationComplete, and pass the esri map component cbm as the data part of the event.
Have a listener in the main ViewNavigatorApplication class that listens for this event. In the handler of the event listener, you can access this through event.data, and then assign it to a variable declared in the main class or in the UserGeolocation class.
Brian
Just to underscore the original intent of the question: I want an absolute reference to a View in a ViewNavigatorApplication. I'm surprised there's no clear way of doing this in the API, since it seems common practice to put Flex components in Views, in the form of declarative MXML. Existing methods that manipulate the stack aren't helpful in this regard, because they are either a) conditional upon the active or first view, or b) affect the visual presentation of the application.
There are three general solutions that have been suggested which, oddly enough, focus on problems engendered by multiple stacks in TabbedViewNavigatorApplication and don't mention the ViewNavigatorApplication.
Put the object/component you want access to at the top of the container hierarchy (ie FlexGlobals.topLevelApplication)
Use a lightweight framework
Use events (either custom or existing)
I opted for the first.